Article View: borland.public.jbuilder.java.api
Article #2027Re: When to use interfaces in OOP
From: Joi Ellis [TeamB]
Date: Wed, 27 Jun 2001 12:50
Date: Wed, 27 Jun 2001 12:50
42 lines
2749 bytes
2749 bytes
Dick Gerrits <dgerrits@wvm.nl> wrote: > Hello, > Is the ONLY advantage of interfaces having a set of methods (including a > list of parameters) > which you can use (inherit) for different object/classes? An interface does > not have any implementation, > so you have always write implementation code in the class which implements > an interface !! > That's what I understand about interfaces. But till now I don't really > understand the power/strength > of interfaces in OOP design. The only advantage I see is that you have > always the same methodNAMES and > parameterLIST when using interfaces ! I like interfaces because they allow you to name a generic type of object as a parameter without demanding that the classes of the actual objects being passed extend from some common ancestor. For instance, I have an interface called MushConnector which specifies a certain set of methods which must be implemented. I have a parent class, MushConnection, which implements all of the methods in a generic way. I then subclass that with into TinyMushConnection which replaces some of the generic methods with methods containing remote command syntax unique to TinyMush. If I then decide to implement a MushConnector for a game which has no resemblance to Mush at all, say StarshipTraders, then I can create a brand new parent class, implement MushConnector in it, and still pass objects of that class into my display gui. The Gui declares its methods to be of type MushConnector, not MushConnection. This is much more flexible than if I demanded everything extend MushConnection itself. One of the interfaces I use the most is Runnable. This lets you turn any class into its own thread, without having to extend the Thread class itself. -- Joi Ellis (TeamB) http://www.teamb.com/ No direct email, please. For best results, post on news server newsgroups.borland.com! Newsgroup Info: http://www.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<3b39d697$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews!not-for-mailReferences:
<3b39c705_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,a43ea4662650fd72
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2001-06-27 06:01:09 PST
Message-ID: <3b39d697$1_1@dnews>
From: "Joi Ellis [TeamB]" <joi@aravox.com>
Subject: Re: When to use interfaces in OOP
Newsgroups: borland.public.jbuilder.java.api
References: <3b39c705_1@dnews>
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.16-3 (i686))
NNTP-Posting-Host: 209.46.41.66
Date: 27 Jun 2001 05:50:31 -0700
X-Trace: dnews 993646231 209.46.41.66 (27 Jun 2001 05:50:31 -0700)
Lines: 42
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews!not-for-mail