• Post Reply Bookmark Topic Watch Topic
  • New Topic

interface example II  RSS feed

 
barclay mcdaniel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help (per 'interface example')... maybe this, - objects are created from the blueprints that classes (class files) provide; -interfaces provide verbs/actions that these class intances/objects utilize OR, interfaces provide non-traditional verbs/meathods for objects (meaning that the traditional verb/meathods exist in their class blueprint... does this sound ok?

barclay
[ April 21, 2008: Message edited by: barclay mcdaniel ]
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First part, yes, second part, I don't think so, no.

A class is a blueprint for an object, maybe a Radio object. The Radio object will probably implement an ElectronicDevice interface, which has turnOn() and turnOff() methods. But the interface doesn't say how those methods are supposed to be implemented; that is for the class to do, to implement those methods (which is by the way why you say "implements").
You now know that if you can call something an ElectronicDevice, it can be turned on and turned off. But you don't know how, nor worry about it. You just turn it on and turn it off.

Yes, the interfaces provide the "verbs" without specifying how they are to be carried out.
 
barclay mcdaniel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interesting, so another words, in an interface_name.java file: you only list the name of the method w/o any operations, the method 'work' is specified in the calling class itself... is this correct, that by putting actions inside an interface_name.java file, you are making a mistake- java's oop is designed/planned so that 'only' method/verb names come from the interface, not the acutal 'how' the 'verb' is carried out... correct?
[ April 21, 2008: Message edited by: barclay mcdaniel ]
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are correct. An interface specifies what is to be done, not how to do it. The only thing you put in the method of an interface is a ; and any implementing classes have to fill out the code. You even miss out the "public" because the compiler takes it for granted that you will implement all those methods with public modifiers.

Have a look at the Comparable interface. Now unzip the class files for, say, String, Integer and Double. You will find them all in a document called "src.zip" which you can usually find inside your Java installation directory, then look under java->lang. If you unzip the Comparable file, you will see there is nothing in its solitary method (but it is generic in more recent versions of Java, so it says "Comparable<T>". Now find the compareTo methods in String Integer and Double. They should be labelled "specified by compareTo in Comparable" or similar in their leading comments.
Read how the three methods work. You can see that they all do the same thing, but they do it completely differently.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the bit about "specified by" doesn't appear.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!