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
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!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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
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!