I’ve been programming in Object Oriented languages for decades. The first OO language I used to be C++ and then Smalltalk and finally .NET and Java. I was gung-ho to leverage the benefits of Inheritance, Encapsulation, and Polymorphism. The Three Pillars of the Paradigm. I was eager to gain the promise of Reuse and leverage the wisdom gained by those who came before me in this new and exciting landscape.
I couldn’t contain my excitement at the thought of mapping my real-world objects into their Classes and expected the whole world to fall neatly into place.
Inheritance, the First Pillar to Fall
At first glance, Inheritance appears to be the biggest benefit of the Object-Oriented Paradigm. All the simplistic examples of shape hierarchies that are paraded out as examples to the newly indoctrinated seem to make logical sense. And Reuse is the word of the day. No… make that the year and perhaps evermore. I swallowed this whole and rushed out into the world with my newfound insight.
Banana Monkey Jungle Problem
With religion in my heart and problems to solve, I started building Class Hierarchies and writing code. And all was right with the world. I’ll never forget that day when I was ready to cash in on the promise of Reuse by inheriting from an existing class. This was the moment I had been waiting for. A new project came along and I thought back to that Class that I was so fond of in my last project.
No problem. Reuse to the rescue. All I got to do is simply grab that Class from the other project and use it. Well… actually… not just that Class. We’re going to need the parent Class. But… But that’s tough… Wait… Looks like we going to also need the parent’s parent too... And then… We’re going to need ALL of the parents. Okay… Okay… I handle this. No problem.
And great. Now it won’t compile. Why?? Oh, I see… This object contains this other object. So I’m going to need that too. No problem.