Skip to main content

#TC201 #Topic4 What is delegation?

1 min read

Delegation is a technique where an object expresses certain behavior to the outside but in reality delegates responsibility for implementing that behaviour toan associated object. This sounds at first very similar to the proxy pattern, but it serves a much different purpose. Delegation is an abstraction mechanism which centralizes object behaviour.

The delegation design pattern allows an object to delegate one or more tasks to a helper object. Two classes are used to achieve this: the delegate and delegator, both which realise a common interface. A method (or methods) on the interface represent the functionality to be delegated. A call to the delagtor calls the matching function on the delegate.