Article View: aus.computers.java
Article #237Re: Multiple interfaces
From: Wayne Berke
Date: Thu, 20 Jun 2002 23:51
Date: Thu, 20 Jun 2002 23:51
62 lines
3430 bytes
3430 bytes
Steve Horsley wrote:
>
> 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.
>
You could do this if you really wanted to do. What you'd have to do is
enhance all your interfaces with an extra method:
Object getContainingObject();
and then implement it this way within the anonymous call:
Intf1 getIntf1()
{
return new Intf1()
{
public void X()
{
intf1X();
}
public Object getContainingObject() {
return <Name of Containing Class>.this;
}
};
}
Admittedly not as easy as in a direct implementation, but it seems to work.
Wayne
Technical Details
Message-ID:
<3D126A72.4123E49B@i.hate.spam>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!feed1.news.rcn.net!rcn!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> <3d121553.1321895@news.virgin.net>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:51:00 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!feed1.news.rcn.net!rcn!not-for-mail From: Wayne Berke <notme@i.hate.spam> Newsgroups: aus.computers.java,borland.public.jbuilder.java.language,comp.lang.java.programmer Subject: Re: Multiple interfaces Date: Thu, 20 Jun 2002 19:51:14 -0400 Lines: 62 Message-ID: <3D126A72.4123E49B@i.hate.spam> 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> <3d121553.1321895@news.virgin.net> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit X-Trace: UmFuZG9tSVbZnAGvkVGt6kOwiXtQroIianEoCGY2mq7/qaEJa+fD6jL9bxgmA5EX X-Complaints-To: abuse@rcn.com NNTP-Posting-Date: 20 Jun 2002 23:50:47 GMT X-Mailer: Mozilla 4.79 [en] (X11; U; Linux 2.0.38 i386) X-Accept-Language: en