|< Free Open Study >|
6.1 Introduction to Multiple Inheritance
I was one of the early C++ programmers who began with C++ version 1.2. At that time, there was a large group of C++ developers screaming for C++ version 2.0. Why? C++ version 2.0 implemented the multiple inheritance (MI) relationship, and version 1.2 did not. Multiple inheritance is the ability for a class to directly inherit from more than one base class. In retrospect, I believe that 49 percent of these screaming developers were screaming because they wanted to misuse multiple inheritance. Another 49 percent screamed because they heard the other 49 percent screaming and jumped on the bandwagon with no real knowledge of why they were screaming. Out of all the screaming developers, only 2 percent understood why they wanted multiple inheritance and were not misusing it. As proof of the multiple inheritance hype argument, I offer the following true story. In the process of peddling a C++ class library consisting of data structure classes, I would invariably be asked, "Does your library use multiple inheritance?" I would reply, "No, but where would you use multiple inheritance in linked lists, hash tables, and stacks?" Their response would be, "I don't know, but my manager said that all of our new tools must have multiple inheritance."
A sudden backlash against multiple inheritance erupted shortly after version 2.0 was released and lots of developers began using it. Statements such as "Multiple inheritance adds no expressive power to C++ and should be removed in the next release, if not sooner!" "Multiple inheritance destroys reusability; get rid of it!" and "I shot off my big toe with multiple inheritance!" were (are) commonplace. The C++ community spent over a year publishing papers debating the use and misuse of multiple inheritance, with no settlement in sight. The position presented and justified in this text is that multiple inheritance does add expressive power to the object-oriented paradigm (and C++ for that matter). It is also one of the most misused features of the object-oriented paradigm. If a design requires multiple inheritance and it is not available at the language level, then the result is accidental complexity. Later in this chapter, we will examine the nature of this accidental complexity in the context of a real-world multiple inheritance example.
This heuristic is not intended to brand MI as evil or even undesirable. It is meant to emphasize the large level of multiple inheritance misuse that exists in many object-oriented designs. When I attend an object-oriented design critique and see a lot of multiple inheritance in the design, I immediately assume that there is a mistake in that portion of the design. I am rarely disappointed in my assumption.
|< Free Open Study >|