Friday, 14 October 2011

Interface v/s abstract class


interface
abstract class
A class may implement several interfaces.
A class may extend only one abstract class.
An interface cannot provide any code at all, much less default code.
An abstract class can provide complete code, default code, and/or just stubs that have to be overridden.
Static final constants only, can use them without qualification in classes that implement the interface. On the other paw, these unqualified names pollute the namespace. You can use them and it is not obvious where they are coming from since the qualification is optional.
Both instance and static constants are possible. Both static and instance intialiser code are also possible to compute the constants.
An interface implementation may be added to any existing third party class.
A third party class must be rewritten to extend only from the abstract class.
If you add a new method to an interface, you must track down all implementations of that interface in the universe and provide them with a concrete implementation of that method.
If you add a new method to an abstract class, you have the option of providing a default implementation of it. Then all existing code will continue to work without change.

No comments:

Post a Comment