Delegation is an extremely powerful pattern in which a delegating object assigns authority to a delegate object. The delegating object keeps a reference to the delegate object and dispatches messages to it.
Dispatch, or message passing, is a concept in object-oriented programming by means of which one object invokes the method of another.
The delegating object uses the delegate object to provide an interface that's similar to an interface of the delegate. In some cases, the delegating object can send a message to the delegate object to just update its own state or that of another object. This is shown in the following diagram:
In other cases, the delegating object assigns responsibility for performing some behavior to the delegate object, as follows:
In this chapter, we'll cover the following topics:
- Types of delegation...