99
The Tragic Death of Inheritance
(avivcarmi.com)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
There are many reasons one might use inheritance. The one which is often first introduced by OOP proponents is creating a “is-a” relationships in some domain model where the goal is to somehow model “real life” with classes and objects.
This always ends badly in my experience. Not worth doing. Just consider the “rectangle square controversy” https://henrietteharmse.com/2015/04/18/the-rectanglesquare-controversy/. Inheritance as a domain modelling tool doesn’t really mean anything outside of textbooks talking about animals and vehicles.
One should understand how computers and programming work and model data in a way which makes sense for the concrete scenario. Look in any algorithms and data structures book. Nothing is ever explained and presented through object models. No UML diagrams needed.
But inheritance also bring actual concrete functionality. In particular dynamic single dispatch. If you need dynamic single dispatch, inheritance is good. That being said, I think that parametric polymorphism (“generics” in OOP terminology) is a better solution than subtype polymorphism in almost all cases. Although languages build around OOP and inheritance sometimes make it too inconvenient to use.