[ajug-members] correct interface programming
webbmorris at yahoo.com
Thu Jul 24 17:41:30 EDT 2008
An interface is a form of contract between the caller and implementation. The caller can generally only see the methods of the interface class (as opposed to the implementation class) because the caller casts the implementation to the interface:
MyInterface mii = (MyInterface)MiiFactory.getAMyInterface();
There is no reason that the caller would have to call all methods of an interface, it only calls the ones it needs. However, the implementation class must implement all methods of the interface it implements. If a method has no use to your situation, you still must implement it, but could leave it empty or throw a run time exception if it is called.
In this fashion, the caller of an interface does not care what the implementation class does, only that the contract of the interface is met.
You can only extend one class, but you can implement as many interfaces as you would like in an implementation class.
I hope this got to the crux of your questions. There are volumes of information out there about Interfaces, Abstract Classes, and Extension that would probably be helpful to you. I don't have any of those links at my fingertips, but I am sure someone will be happy to help.
----- Original Message ----
From: 521 <521 at ofig.org>
To: ajug-members at ajug.org
Sent: Thursday, July 24, 2008 3:43:06 PM
Subject: [ajug-members] correct interface programming
am i saying this correctly?, that which is below... -barclay
if i program to an interface, i do not have to worry about the number of
interfaces that are implemented, do i? but do i not have to use all methods
in an implemented interface? i do have to- it's a contract. correct? and
because you can only extend one class, you have no contract there. correct?
can someone see what my question is?
a tree; a tree can grow, a tree can provide shade; and a tree can provide
lumber for table-tennis.
so my tree class is designed...
then if i am implementing a 'tree'- it depends on which implementation i use
thus have a contract to use certain methods
ajug-members mailing list
ajug-members at ajug.org
More information about the ajug-members