DEV Community

Discussion on: Object Design Style Guide Summary

Collapse
 
migueldevelopez profile image
MiguelDevelopez • Edited

I personally agree with Noback's opinion on this one, I prefer composition by far, but it would be great if you share with me the reasons that you disagree.

Collapse
 
lluismf profile image
Lluís Josep Martínez

Inheritance only leads to a confusing design if misused. It's still a powerful tool for OOP, you simply need to know when and why to use it and do it wisely. There are crappy OOP designs either with inheritance AND composition. Lots of good arguments here softwareengineering.stackexchange....

Thread Thread
 
leocavalcante profile image
Leo Cavalcante

"need to know when and why to use" - This argument can be applied to literally everything, then there is no point in discussing at all. Even something like, Idk, global vars for example, you can say "Well, you just need to know when and why to use". The eval() function: "Well, you just need to know when and why to use". Gotos statements: "Well, you just need to know when and why to use".
Literally everything can go bad if misused, that is a weak argument IMO.

The point is that Inheritance easily leads to misuse which causes confusion and makes it an error prone tool. Good tools should avoid users to make mistakes and the point is that Inheritance isn't one of this tools, that is what the author means by "mostly leads to".

Thread Thread
 
lluismf profile image
Lluís Josep Martínez

Well, I don't apply it to literally everything, that's a poor argument. I still think that inheritance is a very powerful tool, as is polymorphism. You can't have one without the other. If you don't want to use it because you think is bad, it's your choice. I have literally hundreds of use cases in which it's exactly the tool to use.