3 ms·
"what we really mean, and want, is code reuse" I'm not sure if you meant it this way, so I'll underscore this point. Code reuse is truly the worst "reason" to
by sunir 13y ago
"what we really mean, and want, is code reuse"
I'm not sure if you meant it this way, so I'll underscore this point. Code reuse is truly the worst "reason" to use inheritance, and in fact an anti-pattern.
Composition is the only proper way to reuse code because composition is explicitly stating you are using the composed code.
- jroseattle 13y ago"Composition is the only proper way to reuse code because composition is explicitly stating you are using the composed code." And every other pattern is not suggesting this very same thing?
- parasubvert 13y agoYou're taking it too far. One should prefer delegation/composition in most cases, but if you're trying to direct users to a restricted reuse model (inheritance), then it works fine and is often a much clearer approach than "Joe's custom delegation model". There are plenty of examples of this in practice - someone pointed out NeXT/Apple's UIKit for example elsewhere in this thread (which also uses composition where appropriate). The Java collections hierarchy is also a good one (LinkedHashSet < HashSet < AbstractSet).