Implementing an interface and extending (inheriting) a base class are very similar but subtly different ways to achive polymorphism.
Say you make a method that takes a List argument
If we look in the JavaDoc we see List is an interface. You know that any object that comes into your method has the methods promised by the List interface, but you don't have to know any more than that. Ignoring certain details so you can concentrate on the important bits - the argument implements List - is the heart of "abstraction".
Now let's look at a method that requires a base class:
If we look at the
doc we find Observable is a class, not an interface. Again we know that the argument passed has all the methods and fields promised by Observable. Further we know that the argument extends Observable. This is more knowlege, less abstract.
Both ways we get polymorphism - callers can pass us objects of classes that we've never heard of before, we can call the methods we have been promised, and those methods can do different things appropriate to the different classes. Interface is a little more abstract which is usually A Good Thing for us. With extends the caller gets some behavior from the base class which may also be A Good Thing for him.
Is that the right kind of discussion?
[ May 31, 2005: Message edited by: Stan James ]