It's another sort of abstract class. There are also properly abstract class.
It is the Java way to get multiple inheritance. The interface describes
properties and functions that all implementing classes (or extending
interfaces) will have.

Think of it like an electrical interface rather than a GUI. An interface
generally is the point or plane of contact or interaction between different
systems. And that exactly describes how Interfaces in java are generally
used.

Think about it this way.

You are in some sort of Car business which you have to model with Java.
There are many sorts or models of Cars that you deal with. Each model of car
is a concrete class. You have a process (let's call it repair()) that you
apply cars of any model.

While you **could** have a super-class Car and extend each specific model as
a sub class of Car, the problem lies with defining the common methods of
Cars. Lets say, extractMotor() is a part of repair(). Now each car has to
override the extractMotor() method of the super-class Car to get at the
specific procedure of each Car's motor removal. Worse, your
VehicleRepairShop, could have to implement a repair() method for each and
every Model of Car!!! A similar analogy to the Car problem with also apply
to the Motor of each Car. Also, the problem is a particular Model not only
needs to extend 'Car', but also 'Make' (eg Toyota, Lexus, Mercedes etc).

So you could write three interfaces, Car, Motor and Make.

Then for each Make you write a concrete class e.g. Lexus, Mercedes. This
might contain warranty procedures and dealer contact information and such.

Then each Model is a sub-class of the relevant Make class which implements
the Car class (or in the case of Honda, some might implement Car and others,
Motorcycle, or for Mercedes and Volvo, Car, Truck, and Bus ... and all of
these interfaces can extend a Vehicle super-Interface).

So your repair() method just takes the type Car. similarly the
extractMotor() in Car returns a type Motor. The specifics of exactly how
that particular Motor is taken out of the particular model of Car is left up
to the implementing class.

More information than this simple and imprecise illustration can undoubtably
be obtained from the Sun website or any good general Java or OO book.

regs
scot.


-----Original Message-----
From: William Rice [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 4 December 2002 15:50
To: JDJList
Subject: [jdjlist] Re: interface for only 1 class


Sorry to but in, but I see you guys are talking about interfaces in JAVA.  I
have been working with JAVA for about three months and I have come upon code
that uses the JAVA interface,

I have worked in visual coding suce as visual foxpro and visual basic and
when I here the word interface I think about a GUI.

What is the significance of the INTERFACE.
-----Original Message-----
From: James Stauffer [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 03, 2002 2:05 PM
To: JDJList
Subject: [jdjlist] Re: interface for only 1 class


How do you balance that will all of the times that an interface isn't
necessary?  Another aspect is that an interface usually makes it more
complex.  If there is no foreseeable need for an interface when should you
use an interface and when shouldn't you?

James Stauffer
-----Original Message-----
From: Greg Nudelman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 03, 2002 12:28 PM
To: JDJList
Subject: [jdjlist] Re: interface for only 1 class


It depends.  Let's say you only expect to use Oracle DB in the foreseeble
future.  So you write your driver loading, and persistance all over the
place, and create it only for the Oracle.  But in 12 months, your business
folks decide to try and sell the system to some customer, who just got to
have SQL Server.  If you wrote persistence as an interface, it is a snap,
otherwise, some work and re-testing af the whole thing may be involved.

Sounds funny, but this is a real-life example.

Greg
-----Original Message-----
From: James Stauffer [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 03, 2002 7:54 AM
To: JDJList
Subject: [jdjlist] interface for only 1 class


Is it good to have an interface if there will only be one class to implement
it in the foreseeable future? Does it add unnecessary complexity? It usually
isn't much more complex but does that extra complexity add extra value?
Agile programming seems to say "don't build it because you won't need it."
What do you think?
James Stauffer
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________


____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to