Article View: borland.public.jbuilder.java.api
Article #2033Re: When to use interfaces in OOP
From: Valentino Kyriakides
Date: Thu, 28 Jun 2001 19:47
Date: Thu, 28 Jun 2001 19:47
91 lines
4337 bytes
4337 bytes
Joi and Michael Rachow have shown you in a more practicle way what
interfaces are good for. I will instead try to give you an absolute short
and typical common OO sense example to ...why interfaces at all are useful.
In OO languages like C++, Eiffel etc. which support multiple inheritance, a
class can inherit from many ancestor classes, which allows some degree of
inheritance flexibility for OO modeling. E.g. inheritance like the following
is there possible:
father mother
\ /
\ /
child
NOTE that I don't diskuss deeply here any name/method... clashing issues,
which can result from the multiple inheritance scheme, like in the following
scenario:
A
/ \
/ \
B C <- B and C inherit both from A
\ /
\ /
D <- inherits from all the above, thus also the stuff from A via
B and C and so D inherits two times everything from A.
So in the above A, B, C, D scenario the OO language must provide some
mechanism which prevents and solves such possible name/method... clashing
issues. Languages like Eiffel offer here some quite good working build in
language constructs which prevents trouble or the other way said, which
allow you to exactly define from which B or C you want to inherit everything
from A.
Now say you have any single OO inheritance language like Smalltalk,
Objective-C, Java... etc., how would or could you easily model something
like the above without some supporting multi-inheritance OO construct? And
that's exactly the point, where Interfaces play a big role. In single
inheritance languages like Smalltalk, Obj-C and Java you have a slightly
different, but even powerfull interfaces construct, which allow you an even
flexible modeling and which helps to overcome the missing multiple
inheritance theme. - However, it's often said that multiple inheritance is
bad, worse and not the modelers friend, but if it is used with care and in
well thought modeling, it can be really helpfull and also has it's
advantages in certain modeling problem domains. - But all in all, you don't
really need multiple inheritance, with the help of build in OO language
constructs like interfaces and some good proven design patterns, you can
model really everything and often also in some more flexible way!
Valentino
Dick Gerrits <dgerrits@wvm.nl> schrieb in im Newsbeitrag:
3b39c705_1@dnews...
> Hello,
>
> I am new in JAVA/OOP and have a question about using interfaces.
> When do you have to use interfaces? I read some information about the use
of
> interfaces in JAVA/OOP, but I don't understand the advantage/strength of
> interfaces.
>
> 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 !
>
> Please, can anyone tell me more about it ?
>
> Thank you in advance for your reply.
>
> Witte van Moort B.V.
> Dick Gerrits
>
>
> -0-0-0-0-0-0-
>
>
Technical Details
Message-ID:
<3b3b87ca_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<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-28 12:41:49 PST From: "Valentino Kyriakides" <vkyr@ision.net> Newsgroups: borland.public.jbuilder.java.api References: <3b39c705_1@dnews> Subject: Re: When to use interfaces in OOP Date: Thu, 28 Jun 2001 21:47:38 +0200 Lines: 93 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 NNTP-Posting-Host: 195.180.208.149 Message-ID: <3b3b87ca_1@dnews> X-Trace: dnews 993757130 195.180.208.149 (28 Jun 2001 12:38:50 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews