next up previous contents
Next: Frameworks Up: Object Oriented Design Previous: Object Composition vs. Inheritance

Delegation

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.



Paul John Rajlich
Mon May 4 16:53:57 CDT 1998