| Index: > A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
|
|||||
It is called the 'diamond' problem because of the shape of the class inheritance diagram in this situation. 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.
Some languages solve this problem by prohibiting from inheriting the same class twice. Java only allows the multiple inheritance of interfaces, which never have any methods implemented in them. C++ allows the diamond situation, but requires the shared ancestors' inheritance to be specifically marked as virtual, which will make the run time system to ensure that only one instance of the base class is created for and used by an object. Eiffel handles this situation by a select and rename directives, where the ancestors' methods to use in a descentant are explicitly specified. This allows to share the methods of the base class between its descentants or even to give each of them a separate copy of the base class. Perl handles this by specifying the inhertitance classes as an ordered list. In the above ambiguity, class B and its ancestors would be checked before class C and its ancestors, so the method in A would be inherited through B.
Object-oriented programming