Thursday, July 30, 2009

Abstraction vs Interfaces

Abstraction: Default implementation of set of methods.
Compulsive use of extends variable and overriding of default functionality
Better to be used in application framework where a default implementation is required in case component does not implement their own. Like event handling service, Messaging service etc..
If variables changes often then use abstraction

Interfaces: Abstract methods and final variable
Provide conceptual structure to whole application.
Allow Multiple inheritance
If methods are changed frequently then use interfaces.

For example: Interfaces/ Need for multiple inheritance

Two kind of people: actor / director ..
for each of them we define one interface but now what if there is third kind for people who are both actors and directors....

In such scenario we need multiple inheritance...

Need fr abstraction:

Abstraction in big application framework to define default handling.


Inheritance vs. Abstraction
When functionality is to be imposed on unrelated classes then use interfaces...
When functionality is to be used on related classes then use abstraction..

Related classes: GenericList singlelinklist doublelinklist... all have the similar properties and methods...

Unrelated Classes: some function in interface which should be implemented by many component in the system.

No comments:

Post a Comment