|
|
|
|
|
by tigershark
3629 days ago
|
|
Composition increases boilerplate code.
With simple inheritance hierarchies there is an inherent advantage in this regard.
If you use inheritance you don't need to encapsulate the "base" object and implement all the methods of the interfaces doing most of the time just a routing to the base object, you can just extend from the abstract base object and implement only the methods that you need.
Obviously if your hierarchy is complex then it is much better to use composition to have a better decoupling, but it has nothing to do with decreasing the boilerplate code.
Composition and inheritance are just two tools for different jobs.
If someone says Composition > Inheritance it is like saying Screwdriver > Hammer, a complete non-sense.
There is no tool that is inherently good or bad, it all depends how the craftsman uses it (or don't) in a good or bad way for the job. |
|
You're stretching a bit too far. Inheritance is nothing but composition with some default implicit virtual method routing. You admit as much in your comment. If you want tools, it's more like a hammer vs a mallet and a prybar. Same tools, same purpose, just one is bundled.