Article View: aus.computers.java
Article #288Re: Multiple interfaces
From: Coho (Richard Swain)
Date: Tue, 18 Jun 2002 18:40
Date: Tue, 18 Jun 2002 18:40
87 lines
3291 bytes
3291 bytes
Use Facets.
interface Intf1{
public void X();
}
interface Intf2{
public void X();
}
class MyClass
{
private void intf2X()
{
// do interface 2 X() implementation
}
private void intf1X()
{
// do interface 1 X() impementation
}
Intf1 getIntf1()
{
return new Intf1()
{
public void X()
{
intf1X();
}
};
}
Intf2 getIntf2()
{
return new Intf2()
{
public void X()
{
intf2X();
}
};
}
}
Then you can use myclassinstance.getIntf2().X() or
myclassinstance.getIntf2().X() depending which you want to use/call.
Rich.
Darryl L. Pierce wrote:
> On Mon, 17 Jun 2002 00:56:34 -0400, Tristan Reeves wrote:
>
>
>>Nothing in particular, it's a general observation related to custom
>>interfaces:
>>
>>interface Intf1{
>> public void X();
>>}
>>
>>interface Intf2{
>> public void X();
>>}
>>
>>class MyClass implements Intf1, Intf2{
>> ????
>>}
>
>
> 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
> _any_ method, and that solves the problem of "which inherited
> implementation to invoke first".
>
> HTH.
>
--
http://www.krang.f9.co.uk
Technical Details
Message-ID:
<3D0F7E91.5010401@krang.f9.co.uk>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.vmunix.org!newsfeed.stueberl.de!newspeer1-gui.server.ntli.net!ntli.net!newsfep1-win.server.ntli.net.POSTED!53ab2750!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>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: 10d6db,113f3357bc588129 X-Google-Attributes: gid10d6db,public X-Google-Thread: f74b3,113f3357bc588129 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2002-06-18 11:39:54 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.vmunix.org!newsfeed.stueberl.de!newspeer1-gui.server.ntli.net!ntli.net!newsfep1-win.server.ntli.net.POSTED!53ab2750!not-for-mail Message-ID: <3D0F7E91.5010401@krang.f9.co.uk> From: "Coho (Richard Swain)" <vibron@krang.f9.co.uk> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en,ru MIME-Version: 1.0 Newsgroups: aus.computers.java,borland.public.jbuilder.java.language,comp.lang.java.programmer Subject: Re: Multiple interfaces 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> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Lines: 88 Date: Tue, 18 Jun 2002 19:40:17 +0100 NNTP-Posting-Host: 80.4.128.208 X-Complaints-To: abuse@ntlworld.com X-Trace: newsfep1-win.server.ntli.net 1024425588 80.4.128.208 (Tue, 18 Jun 2002 19:39:48 BST) NNTP-Posting-Date: Tue, 18 Jun 2002 19:39:48 BST Organization: ntlworld News Service