Article View: aus.computers.java
Article #238Re: Multiple interfaces
From: Darryl L. Pierce
Date: Thu, 20 Jun 2002 19:51
Date: Thu, 20 Jun 2002 19:51
52 lines
2973 bytes
2973 bytes
On Thu, 20 Jun 2002 13:01:31 -0400, Tris Orendorff wrote:
>> What's the problem with the above? In true multiple inheritance, where
>> you're inheriting multiple _implementations_, the diamond-of-death
>> occurs where you're not sure which _inherited_ implementation to invoke
>> first, or whether it's desirable to invoke one first. With Java, you
>> have multiple inheritance on at the _interface_ level, which alleviates
>> the diamond-of-death problem: you only have one inherited
>> implementation on
>
> I'm sorry. What exactly is the "the diamond-of-death?"
In C++, you can have the following:
class Base
{
public:
virtual void doFoo();
};
class Child1:public Base
{
public:
void doFoo();
};
class Child2:public Base
{
public:
void doFoo();
};
class Grandchild1:public Child1,Child2
{
public:
void doFoo();
};
Child1 and Child2 inherited Base and override the dooFoo() method.
Grandchild1 inherits _both_ Child1 and Child2, and overrides doFoo().
Now, when Granchild1::doFoo() invokes the methods inherited, _which_ one
does it invoke first? That is the diamond-of-death, and is avoided by
Java's not allowing multiple inheritance of _implementations_. You no
longer have to decide which implementation you're inheriting to invoke
first, since you can only inherit _one_.
HTH. =)
--
Darryl L. Pierce <mcpierce@databasix.com>
Visit the Infobahn Offramp <http://welcome.to/mcpierce>
"What do you care what other people think, Mr. Feynman?"
Technical Details
Message-ID:
<pan.2002.06.20.15.51.27.428100.3999@databasix.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!DirecTVinternet!DirecTV-DSL!nopics.sjc!not-for-mailReferences:
<1024283082.192985@web.apex.net.au> <JScP8.111$Fv1.17660@newsread2.prod.itd.earthlink.net> <1024289793.45649@web.apex.net.au> <pan.2002.06.17.07.46.24.235390.777@databasix.com> <Xns92338482819E2RepublicPicturesLtd@142.77.1.194>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10a146,113f3357bc588129 X-Google-Attributes: gid10a146,public X-Google-Thread: f74b3,113f3357bc588129 X-Google-Attributes: gidf74b3,public X-Google-Thread: 10d6db,113f3357bc588129 X-Google-Attributes: gid10d6db,public X-Google-ArrivalTime: 2002-06-20 16:53:14 PST From: "Darryl L. Pierce" <mcpierce@databasix.com> Subject: Re: Multiple interfaces Date: Thu, 20 Jun 2002 15:51:33 -0400 Newsgroups: aus.computers.java,borland.public.jbuilder.java.language,comp.lang.java.programmer Organization: Just me on my wife's computer... Message-ID: <pan.2002.06.20.15.51.27.428100.3999@databasix.com> References: <1024283082.192985@web.apex.net.au> <JScP8.111$Fv1.17660@newsread2.prod.itd.earthlink.net> <1024289793.45649@web.apex.net.au> <pan.2002.06.17.07.46.24.235390.777@databasix.com> <Xns92338482819E2RepublicPicturesLtd@142.77.1.194> User-Agent: Pan/0.11.2 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Comment-To: "Tris Orendorff" <triso@remove-me.netrover.com> NNTP-Posting-Host: nopics.sjc X-Trace: nopics.sjc 1024617185 64.192.144.133 (20 Jun 2002 16:53:05 -0700) Lines: 52 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!DirecTVinternet!DirecTV-DSL!nopics.sjc!not-for-mail