The diamond problem

The diamond problem is an ambiguity that occurs when two classes B and C inherit from A, and a fourth class D inherits from both B and C. If A implements a method foo(), and B and C override it, then what exact implementation does D have by default? The diamond problem is obvisouly only possible in languages that allow multiple inheritance, for example Java doesn't have this problem (but Java 8 does because it allows default method implementation in interfaces). The Wikipedia article discusses the various solutions offered by different OOP languages, but I also liked this other article that analyzes how composition is often better than inheritance.


Popular Posts