By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,423 Members | 1,294 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,423 IT Pros & Developers. It's quick & easy.

interface inheritance - worth getting rid of this diamond?

P: n/a
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-lit....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
em**************@fastmail.fm
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
This very topic is discussed here:
http://msdn.microsoft.com/library/de...gLanguages.asp

Look for "Single Inheritance"

/Ole

"emma middlebrook" <em**************@fastmail.fm> wrote in message
news:e2**************************@posting.google.c om...
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-lit....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
em**************@fastmail.fm

Nov 16 '05 #2

P: n/a
On 18 Apr 2004 15:32, em**************@fastmail.fm (emma middlebrook)
wrote:
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-lit...ce.html#faq-25.
8 <snip>
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 -

--
Simon Smith
simon dot s at ghytred dot com
NewsLook - NNTP Client for Outlook
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.