posted 22 years ago
Hi,
There is one definition of abstract class that I can think of - If you are certain that the instance of class can ONLY be one of the subtypes instances then define that class as abstract.
Larman (Applying UML and Patterns) illustrates this with an example of Payment as an abstract class, since its instance can only be of Cash,Credit and Check types.
Another use of abstract class is in Template pattern - An abstract class contains a concrete method and another non-concrete/abstract methods.These abstract methods are implemented in the subtypes.In the abstract class, the non-concrete methods are called in the concrete method, i.e the basic template of what needs to be done is defined in the abstract class.
As regards interface, one definition which I can think of is instance of a class can't be predicted.The class could then be defined as an interface, where the concrete subtypes which implement this interface could act as different plug-ins.
Would also like to add, that when you extend a class, you are inheriting both the capability and responsibility of the superclass.However, when you implement the interface, you are only inheriting the responsibility of the supertype.
Hope this helps,
Sandeep
[This message has been edited by Desai Sandeep (edited June 28, 2001).]