interface inheritance - worth getting rid of this diamond?

E

emma middlebrook

Hi

I come from a C++ background and so am familiar with the 'dreaded
inheritance diamond' i.e. the ambiguity of which data to use when a
class appears twice in the hierarchy. Here's a link for anyone not
familiar: http://www.parashift.com/c++-faq-lite/multiple-inheritance.html#faq-25.8
..

Base
/ \
/ \
/ \
Der1 Der2
\ /
\ /
\ /
Join

Now to my question ... I know an interface inheritance hierarchy of
the same configuration doesn't suffer any problems at all but, to me,
seeing it in a class diagram still makes me feel a little queasy from
a design correctness point-of-view. If anyone feels the same, how do
they best get round the problem. If you don't feel queasy, would you
tell me why I shouldn't either!

Finally, in my particular case I have interfaces IBase and IDerived
(the latter derived from the former), Concrete deriving from IBase,
and then DerivedConcrete deriving from both Concrete and IDerived.
Hence the diamond.

IBase
/ \
/ \
/ \
IDerived Concrete
\ /
\ /
\ /
DerivedConcrete


Thanks very much for your help!

Emma Middlebrook
(e-mail address removed)
 
S

Simon Smith

Hi

I come from a C++ background and so am familiar with the 'dreaded
inheritance diamond' i.e. the ambiguity of which data to use when a
class appears twice in the hierarchy. Here's a link for anyone not
familiar:
http://www.parashift.com/c++-faq-lite/multiple-inheritance.html#faq-25.
8
Now to my question ... I know an interface inheritance hierarchy of the
same configuration doesn't suffer any problems at all but, to me,
seeing it in a class diagram still makes me feel a little queasy from a
design correctness point-of-view. If anyone feels the same, how do they
best get round the problem. If you don't feel queasy, would you tell me
why I shouldn't either!

Finally, in my particular case I have interfaces IBase and IDerived
(the latter derived from the former), Concrete deriving from IBase, and
then DerivedConcrete deriving from both Concrete and IDerived.
Hence the diamond.

IBase
/ \
/ \
/ \
IDerived Concrete
\ /
\ /
\ /
DerivedConcrete

This is one reason that you can explicitly define interface methods, as:

private whatever IDerived.MethodFromIBase() {}

To use it a client would have to cast Concrete to Iderived - thus explicit
usage. It's a bit messy, true, and I'd wonder about the design, but not
nearly as bad as MI.
Cheers -
 
Top