> So here is my question what do you mean by "clients are not allowed > to implement the interface (instead they use it)".
>
> How would I be using such an interface. Am I missing a point here.
I have to say that I was a bit puzzled by this at first too.
Would I be correct in thinking that "using" and not "implementing" means something like
public void myMethod( Map myMapOfStuff )
{
...
String myValue = (String) myMapOfSuff.get( "MyKey" );
...
}
since I am "using" the
Map
interface but not "implementing" it directly in my code. In the above example I would probably be calling the method with something like a
HashMap
instance that I'd populated.
Mind you, if the
Map
interface was given a new method, the
HashMap
implementation would have to implement it right? This is where Erich's point about abstract classes is true...
In Java when you add a new method to an interface, you break all your clients. When you have an abstract class, you can add a new method and provide a default implementation in it.
If HashMap extended an abstract class (which implemented Map) then you could fling a new method into Map and add a default implementation to the abstract class. So HashMap would not break - but would have the opportunity to implement the new method locally if it wants.
I don't know if this (a) helps anyone (b) is rubbish or (c) is a statement of the bleeding obvious!
Anyway, there's my input.
Jaydee