DEV Community

Discussion on: The Four Pillars of Object Oriented Programming

Collapse
 
jonathanhiggs profile image
Jonathan Higgs

I think composition is far more important than inheritance and polymorphism, and the lack of attention it recieves is often to the detriment of OOP as a whole. Take the animal inheritance as an example, in almost every case except trivial examples the use of composition reduces code complexity. e.g. similar traits or features evolved in distinct evolutionaly trees, so you would have to repeat the implementation in multiple places. Continuing the evolutionary example, there are cases of traits evolving and then being lost which also wouldn't work with an inheritance style of programming

Collapse
 
toddster79 profile image
Todd Carlson

I 100% agree! My favorite instructor said that when it comes to inheritance, you almost always get the hierarchy wrong. He was a champion of composition too!