Although object composition is very useful, one may question whether it is as powerful
for reuse as inheritance. Specifically, using inheritance, an inherited method can always
refer to the receiving object using the this
member variable in C++. In delegation,
the receiving object delegates operations to a delegate (one of the objects it is composed of).
The same effect (as this
) is achieved by having the receiving object pass a reference
to itself to the delegate. Using delegation, a method can always
refer to the original recipient of the message, regardless of the number of indirections
due to object composition.
Delegation allows object composition to be as powerful for reuse as inheritance [7]. Several design patterns make use of this strategy.