liveBook · Manning

Diamond problem

As explained in Data-Oriented Programming: Reduce software complexity

The diamond problem is ambiguity caused when a class inherits from two classes that share a common ancestor.

A feature that looks tiny can turn a class hierarchy into a maze. The diamond problem appears when class D inherits from classes B and C, while both B and C inherit from A, creating ambiguity about shared behavior. section 1.2.4

When member types collide

Theo moves addBookItem from Librarian into UserWithBookItemRight so Librarian and VIPMember can share it. But VIPMember extends both Member and UserWithBookItemRight, and both extend User. Adding Super members makes the hierarchy more complex, producing three “Deadly Diamonds of Death.” section 1.2.4

Figure 1.16 A class diagram for a system with VIP members

Inspect the class diagram showing how VIPMember introduces the diamond through Member, UserWithBookItemRight, and User. section 1.2.4

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Defines the inheritance shape and traces its emergence through successive class-diagram changes and a workplace narrative.
Examples
Uses Librarian, Member, VIPMember, Super members, UserWithBookItemRight, and User in successive class diagrams.
What you can do after
Evaluate/understand why adding behavior through multiple inheritance can produce ambiguous and increasingly complex class designs.
How it connects
Connects multiple inheritance with class hierarchies, shared base classes, ambiguity, and regression testing.

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.