Article View: aus.computers.java
Article #235Re: Multiple interfaces
From: Steve Horsley
Date: Thu, 20 Jun 2002 18:01
Date: Thu, 20 Jun 2002 18:01
53 lines
3540 bytes
3540 bytes
On Wed, 19 Jun 2002 23:12:14 +0100, "Coho (Richard Swain)"
<vibron@krang.f9.co.uk> wrote:
>> almost need to create a new interface:
>>
>> interface ThingThatDoesIntf1AndIntf2 {
>> Intf1 getIntf1();
>> intf2 getIntf2();
>> }
>>
>> Except that you can't even pass this object round to a method that
>> expects to be given an Intf1 or an Intf2.
>
>But I don't see how using somekind of namespace resolution is
>polymorphic either. i.e to specify which method to call you *have*
>to specify the interface the method is on. IMHO getIntfN() does that
>just as well as some kind of language trick.
>
Me neither. Perhaps the best approach is to use a convention like:
public void intf1_draw()...
public void intf2_draw()...
but I don't think people are likely to adopt it.
>You are right about specifying a new interface, but I would hope that
>practically all concrete classes are expressions of interfaces - to
>which those two methods can be added.
>
>If a method takes a particular interface intf1 say you can always do
>
>theMethod( myclass.getIntf1() );
>
That's not too bad. Except that there's no way to get back from the
Intf1 to the original myClass object. I'm not sure you should ever
want to, but I still feel alienated by this somehow.
>and within that if you need to get hold of the other interface just do
>
> Intf2 f2 = ((ThingThatDoesIntf1AndIntf2)fi).getIntf2();
>
>For your last point. If a method takes an object of type intf1 *or*
>intf2 I'm not quite sure how it suppose to know which X() is the one to
>be called internally unless they they are functionally equivalent and
>hence the same method, or unless the object being passed in is only an
>implementation of one of the interfaces, in which case no specific
>resolution is required.
Bad wording on my part. I meant "a method that expects to be given an
Intf1 or a method that expects to be given an Intf2."
I just don't think there's a really good solution, but as others have
pointed out, it fortunately doesn't arise very often.
Steve
Technical Details
Message-ID:
<3d121553.1321895@news.virgin.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!news-hog.berkeley.edu!ucberkeley!newshub.sdsu.edu!west.cox.net!cox.net!newspeer1-gui.server.ntli.net!ntli.net!news6-win.server.ntlworld.com.POSTED!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> <3D0F7E91.5010401@krang.f9.co.uk> <3d10edc6.1491361@news.virgin.net> <3D1101BE.40506@krang.f9.co.uk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,113f3357bc588129 X-Google-Attributes: gid10d6db,public X-Google-Thread: f74b3,113f3357bc588129 X-Google-Attributes: gidf74b3,public X-Google-Thread: 10a146,113f3357bc588129 X-Google-Attributes: gid10a146,public X-Google-ArrivalTime: 2002-06-20 10:54:47 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!news-hog.berkeley.edu!ucberkeley!newshub.sdsu.edu!west.cox.net!cox.net!newspeer1-gui.server.ntli.net!ntli.net!news6-win.server.ntlworld.com.POSTED!not-for-mail From: steve.horsley1@virgin.net (Steve Horsley) Newsgroups: aus.computers.java,borland.public.jbuilder.java.language,comp.lang.java.programmer Subject: Re: Multiple interfaces Message-ID: <3d121553.1321895@news.virgin.net> 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> <3D0F7E91.5010401@krang.f9.co.uk> <3d10edc6.1491361@news.virgin.net> <3D1101BE.40506@krang.f9.co.uk> X-Newsreader: Forte Free Agent 1.21/32.243 Lines: 53 Date: Thu, 20 Jun 2002 18:01:23 GMT NNTP-Posting-Host: 62.253.73.101 X-Complaints-To: abuse@virgin.net X-Trace: news6-win.server.ntlworld.com 1024595681 62.253.73.101 (Thu, 20 Jun 2002 18:54:41 BST) NNTP-Posting-Date: Thu, 20 Jun 2002 18:54:41 BST Organization: Virgin Net Usenet Service