Article View: aus.computers.java
Article #886Re: Interfaces Why?
From: Paul Murray
Date: Fri, 14 Apr 2000 00:00
Date: Fri, 14 Apr 2000 00:00
44 lines
2157 bytes
2157 bytes
> Hi
>
> Can some one tell me why & when you would use an interface?
>
> I know how to write one and how to upcast from the concrete class
> to the interface, I just can't see why you want to do this.
>
> is to protect the other methods?
> are they more "light weight"?
I don't know what upcasting might be. Upsizing and upgrading, yes, but not
upcasting.
Interfaces can permit multiple inheritance, but the main use is in alowing
class hierarchies to specify, uuuh, "plug compatibility". It allows classes
to agree on a set of methods to communicate with one another with.
If class A extends class B, then the meaning is "a B is an A, with extras".
If class A implements I1, I2 and I3, the meaning is "A class A can do I1
stuff, I2 stuff and I3 stuff".
If Class C needs to hold a reference to a class that can do I2 stuff, it can
class C {
I2 i2 = null;
void setI2FaciltyProvider(I2 i2) { this.i2=i2;}
}
Without having to care what kind of class is ultimately doing the things
that an i2 does.
extending classes, OTOH, allows you to biorrow *functionality* from a base
class without rewriting it all.
Repeat after me "intefaces are *specification*, classes are
*implementation*"
Saaay - does anyone know whay they didnt put static methods in interfaces?
You can have static variables.
--------------------------------------------------------------
http://www.users.bigpond.com/pmurray
ICQ: 26066755
Technical Details
Message-ID:
<1_QJ4.1592$E4.2662@newsfeeds.bigpond.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<t4uJ4.4977$5D.10797@ozemail.com.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,129fca08133b7b2e X-Google-Attributes: gid10d6db,public From: "Paul Murray" <pmurray@nospam.bigpond.com> Subject: Re: Interfaces Why? Date: 2000/04/14 Message-ID: <1_QJ4.1592$E4.2662@newsfeeds.bigpond.com> X-Deja-AN: 611377726 References: <t4uJ4.4977$5D.10797@ozemail.com.au> X-Priority: 3 X-Mimeole: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Trace: newsfeeds.bigpond.com 955767805 139.134.125.96 (Sat, 15 Apr 2000 13:03:25 EST) Organization: Telstra BigPond Internet Services (http://www.bigpond.com) X-MSMail-Priority: Normal NNTP-Posting-Date: Sat, 15 Apr 2000 13:03:25 EST Newsgroups: aus.computers.java