| dbpprop:abstract
|
- In object-oriented programming languages with multiple inheritance and knowledge organization, the diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If a method in 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? For example, in the context of GUI software development, a class Button may inherit from both classes Rectangle (for appearance) and Clickable (for functionality/input handling), and classes Rectangle and Clickable both inherit from the Object class. Now if the equals method is called for a Button object and there is no such method in the Button class but there is an overridden equals method in both Rectangle and Clickable, which method should be eventually called? It is called the "diamond problem" because of the shape of the class inheritance diagram in this situation. In this article, 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.
- Das Diamond-Problem entsteht durch Mehrfachvererbung in der Objektorientierten Programmierung und Wissensmodellierung. Es kann auftreten, wenn eine Klasse D auf zwei verschiedenen Vererbungspfaden (B und C) von ein und derselben Basisklasse A abstammt. Zeichnet man die Vererbungsbeziehungen zwischen den Klassen als Diagramm, so ergibt sich die Form einer Raute (englisch rhombus oder diamond), nach der das Diamond-Problem benannt ist. Die Probleme der Mehrfachvererbung lassen sich am Beispiel eines Amphibienfahrzeugs verdeutlichen, das sowohl die Eigenschaften eines Land- als auch die eines Wasserfahrzeuges erbt. Das Diamond-Problem tritt hierbei auf, wenn beide von der Klasse Fahrzeug abstammen, die eine Methode des Fortbewegens besitzt. Die Frage ist nun, ob sich ein Amphibienfahrzeug wie ein Land- oder ein Wasserfahrzeug oder wie ein Land- und ein Wasserfahrzeug fortbewegt. Diese Mehrdeutigkeit kann nur im Einzelfall gelöst werden; so hat ein Amphibienfahrzeug beispielsweise zwei Fortbewegungsarten (-methoden), aber nur ein Gewicht, obwohl Fahrzeug nur eine Fortbewegungsart hat.
- Nei linguaggi di programmazione orientati agli oggetti con ereditarietà multipla, il diamond problem (problema del diamante) è un'ambiguità che si verifica quando due classi B e C ereditano dalla classe A, e la classe D eredita sia da B che da C. Se un metodo in D chiama un metodo definito in A, da quale classe viene ereditato? Il problema è chiamato problema del 'diamante' a causa della forma del diagramma di ereditarietà delle classi. Differenti linguaggi di programmazione hanno risolto il problema in modi diversi: Objective-C, PHP, C#, e Java consentono solo l'ereditarietà singola, ma come compromesso è consentita l'ereditarietà multipla delle interfacce (chiamati protocolli in Objective-C). Le interfacce sono essenzialmente classi base astratte con metodi tutti astratti e nessun dato membro. C# (e altri linguaggi . NET che consentono la definizione di interfacce) consentono la definizione a livello interfaccia. C++ per default segue ogni percorso di ereditarietà separatamente, quindi l'oggetto D contiene due separati oggetti di A. Se l'ereditarietà da A a B e l'ereditarietà da A a C sono entrambe segnate come "virtual", C++ si prende particolare cura di creare solo un oggetto A, l'utilizzo dei membri di A funziona correttamente. Se l'ereditarietà virtuale e l'ereditarietà non virtuale sono mischiate, esiste solo un A virtuale e un A non virtuale per ogni percorso di ereditarietà non virtuale a A.
- 菱形継承問題(英: Diamond problem)とは、多重継承を伴うオブジェクト指向プログラミング言語において、クラス A を2つのクラス B と C が継承し、B と C の両方をクラス D が継承する際に発生するあいまいさを指す用語である。クラス D にあるメソッドが A で定義された(かつ D においてオーバーライドされていない)メソッドを呼び出すとしたとき、B と C がそのメソッドを異なった形でオーバーライドしていたら、D は B と C のどちらのメソッドを継承するのか、という問題である。 例えば、クラス Button は クラス Rectangle(見た目のため)と Mouse(マウスイベントのため)を継承し、Rectangle も Mouse も Object クラスを継承しているとする。ここで Button オブジェクトが equals メソッドを呼び出し、Button クラス自体にはそのメソッドは定義されていないとする。Rectangle と Mouse にはオーバーライドされた equals メソッドがそれぞれ定義されているとしたら、どちらを呼び出すべきか? これが「菱形; diamond」問題と呼ばれるのは、クラス継承図の形状が菱形になるためである。クラス A が頂上にあり、B と C がそれぞれそこから枝分かれし、D がその2つの枝を再び1つにすることで、全体として菱形を形成する。
|
| rdfs:comment
|
- In object-oriented programming languages with multiple inheritance and knowledge organization, the diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C.
- Das Diamond-Problem entsteht durch Mehrfachvererbung in der Objektorientierten Programmierung und Wissensmodellierung. Es kann auftreten, wenn eine Klasse D auf zwei verschiedenen Vererbungspfaden (B und C) von ein und derselben Basisklasse A abstammt. Zeichnet man die Vererbungsbeziehungen zwischen den Klassen als Diagramm, so ergibt sich die Form einer Raute (englisch rhombus oder diamond), nach der das Diamond-Problem benannt ist.
- Nei linguaggi di programmazione orientati agli oggetti con ereditarietà multipla, il diamond problem (problema del diamante) è un'ambiguità che si verifica quando due classi B e C ereditano dalla classe A, e la classe D eredita sia da B che da C. Se un metodo in D chiama un metodo definito in A, da quale classe viene ereditato? Il problema è chiamato problema del 'diamante' a causa della forma del diagramma di ereditarietà delle classi.
|