There are some infamous cases of OOP abuse in the 7 digit LOC embedded system codebase I work in. I have known several developers that created these sorts of overly-engineered inheritance hierarchies seemingly just for their own sake. It’s awful, and it’s even worse when the original author leaves the company and leaves these sorts of unmaintainable blocs in our applications.
But I think there are definitely places where OOP is not only beneficial but just the correct solution for a part of the application. GUI for instance–all the various widget types and how they plug in to the UI system to handle mouse events and get drawn in the correct Z-order–it’s very intuitive. Of course you will find a subclass of a subclass of a subclass of Button every once in a while, and in these cases I do look for opportunities to use composition over inheritance.
By the way - can we talk about the author’s weird definition of composition? I’ve always defined composition as a class with a “has-a” relationship with other classes. But this author still defines it as classes with a “is-a” relationship to other classes, or in this case a single “generation” of inheritance. That seems bizarre to me, especially when they give this example:
In composition, this is a simple task: go to Dog class, add getTreat call in between eating and pooping. Done. 💪
And yet, their example of a Dog class following composition literally inherits from the Animal interface and does not have a point in which Dog can, internally, insert this getTreat() call:
class Dog implements Animal { doStuff() { consumeEnergy() println(“woof”) rest() } }
Lol… anyway, I like the sentiment of the article but I lean much farther toward just picking the correct tool for the job. Inheritance can still be the right solution in many cases and blaming a paradigm for code readability problems doesn’t seem as apt as, say, realizing that even in codebases where every commit has to be reviewed, at the end of the day you still have to ship product and there is never time to keep all code in perfect order, especially in large legacy systems*.
I want do a metal cover of Suni Lee’s floor routine music.