Tuesday, August 28, 2012

The diamond problem

The "diamond problem" (sometimes referred to as the "deadly diamond of death") is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If D calls a method defined in A (and does not override the method), and B and C have overridden that method differently, then from which class does it inherit: B, or C?


It is called the "diamond problem" because of the logical shape of the class inheritance diagram in this situation. Here, class A is at the top, both B and C separately beneath it, and D joins the two together at the bottom to form a diamond shape.

Ref: Wikipedia

No comments:

Post a Comment