I have not carefully read each entry so I may be repeating another answer here.
The way that I look at interfaces is that they establish a tightly defined API.
In my mind, an interface exists so that a programmer/developer can define the method calls required to establish a common programming interface that can be called from any number of places in the program. They do not (CAN not!) enforce a particular implementation. In fact, that is the flixibility that they give you. Each class that implements the interface must provide an implementation of each method that fulfills the "contract" advertised by the API but it must do so in a manner that is correct for this type of object. And so it goes that each object will have it's own implementation BUT each one of them accepts the same set of method calls/signatures.
Where
polymorphism helps us is that, while each different object that implements the interface is actually a different class/object type, a single reference variable of the INTERFACE type can point to any one of them. The actual class type does not matter because polymorphism allows an interface-type reference to point to any of them.
Perhaps a short example.
If I define an interface for my design called Loggable. That interface has one method, makeLogEntry().
Now, I design three classes, PrinterLog, ScreenLog, and FileLog all three of them implement Loggable and each implements makeLogEntry() in a manner appropriate for that logging type (that is to say, PrinterLog has makeLogEntry() go to the printer, ScreenLog makes it go to the screen, and FileLog makes it go to a specified file.
Down in your program code somewhere you will decide which type of logging you wish to do and instantiate the appropriate object.
However, if you declare a reference variable,
Loggable logMethod;
whichever of the below you use will work:
logMethod = new PrinterLog();
or
logMethod = new ScreenLog();
or
logMethod = new FileLog("filename");
After that point, anywhere in your code that you want to make a log entry all you have to do is code in:
logMethod.makeLogEntry("Text of the log entry");
that way, it doesn't matter which class logMethod actually refers to, because of polymorphism and the interface definition, the call will work.
Edited because another thought occurred to me:
Perhaps also, another point of view might be handy....
You haven't lost re-usablility of anything at all. In fact, you are re-using the interface to allow common access to what can be a wide variety of classes!
[ June 13, 2008: Message edited by: Bob Ruth ]
[ June 13, 2008: Message edited by: Bob Ruth ]