design patterns - Why is diamond of death and not triangle of death -
this question has answer here:
- diamond problem 2 answers
i've seen lot examples illustrate dangerous of multiple inheritance.
the example class b , c extends class , class d extends both b , c.
b , c both override method a, example, equals();
then when call d.equals(); doesn't know 1 parent should called
provided equals() not overridden in d.
from can see, isn't class in example redundant? if remove hierarchy , @ b , c, if b , c both have method called equals(), when d extends b , c, still have same problem, isn't triangle of death?
i not sure if assumed cause compile time error in other language.
hope can clarify me.
if d extends b , c
, not overrides method equals()
, implemented in b , c, there no ambiguity - d can use b.equals()
or c.equals()
.
with diamond structure on other hand, if d calls a.equals()
, both b , c override it, don't know method should invoked b.equals()
or c.equals()
.
Comments
Post a Comment