I think the two techniques are intended to address slightly different situations. Inheritance is used where there are one or (more typically) more objects that share a common set of functions (implemented in the base class) but also need to do some similar things differently (the bits that are added or overridden in the subclasses). But all the functions are directly associated with the type of object itself.
As for delegation, I tend to find this appearing when I find that a class is really implementing more than one discrete object. A new class can be extracted from the original one, which makes each one more cohesive, in that they more tightly implement the data and functions associated with one logically separate, er, thing.
I hope some of that makes sense! Was the question rhetorical or did you have a specific situation in mind?
There is also the is-a/has-a/contain-the-doubt analysis methodology. If it is-a thing, it is derrived from the thing. If it has-a thing, it contains the thing. When in doubt, contain the thing.
It's easy to remember, and works very well as a general rule of thumb.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.