By sin on Feb 11, 2008
At design-level, an interface describes the functionalites which could be implemented differently across various implementations. Therefore, it de-couples an architecture in terms of the functionalities. Whereas, an abstract class talks about the responsibilites of the classes under a hierarchy. It creates an inheritance hierarchy where subclasses provide
their own definitions for the inherited methods.
As an example, I might decide to write an interface called Accessor to access a data source.I would design GenericAccessor as an abstract class which implements Accessor. GenericAccessor could implement multiple interfaces to implement a range of functionalities which have been divided across multiple interfaces. So it means that GenericAccessor could be an Accessor and a Listener at the same time. If I were to design GenericAccessor as an abstract class, I would be putting all the functionalities inside the single class which
doesn't me incorporate re-usability into the design.
A few interesting facts:
only final static variables are allowed to be declared.
all the declared methods are public
both instance and static variables are allowed
can have any kind of methods.