liveBook · Manning

Multiple inheritance

As explained in Data-Oriented Programming: Reduce software complexity

Multiple inheritance is a class-inheritance mechanism in which one class derives directly from more than one parent class.

Multiple inheritance lets one class derive from more than one parent, but a quick feature can turn a tidy hierarchy into a maze of overlapping responsibilities. section 1.2.4

When a tiny feature creates three diamonds

A library system adds VIPMember and SuperMember classes. Reusing Librarian::addBookItem through UserWithBookItemRight seems practical, until VIPMember inherits from both Member and UserWithBookItemRight, which themselves inherit from User. Adding SuperMember produces three diamond-shaped ambiguities. section 1.2.4

Figure 1.16 A class diagram for a system with VIP members

Compare the class diagram before and after introducing VIP members to see how shared behavior creates a diamond. section 1.2.4

The practical warning is straightforward:

  • Reuse through multiple inheritance can hide ambiguity rather than remove duplication. section 1.2.4
  • Adding more member capabilities compounds the hierarchy’s complexity. section 1.2.4
  • Interfaces and composition over inheritance become alternatives when the hierarchy stops scaling cleanly. section 1.2.4

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Traces hierarchy changes through a class diagram and identifies diamond ambiguity, but stops short of resolving inheritance semantics.
Examples
Uses User, Member, Librarian, VIPMember, SuperMember, and UserWithBookItemRight in evolving class diagrams.
What it assumes
Assumes familiarity with classes and inheritance, then demonstrates hierarchy complexity through a concrete feature change.
What you can do after
Evaluate class hierarchies for diamond ambiguity and recognize when composition may be safer.
How it connects
Connects multiple inheritance with class hierarchies, interfaces, composition over inheritance, and the diamond problem.

Also explained in

Compare how 4 books explain multiple inheritance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.