Saturday, August 18, 2012

Interface Vs Abstract Class

Interface Vs Abstract Class
A frequent question in interviews is when one should choose Interface and when to go with abstract class?
Interface specifies a "Is-Capable-of" doing something.
Abstract specifies a "Is-a" relation.

I would define a interface when there is necessarily nothing in common but the implementation should do somthing specific.
e.g. Iterator inteface- no specific on what type of data structure and what condition would it iterate.
e.g. Actor who is also a Director.

Abstract is to provide a default behavior. If I expect the system to undergo changes and requires a default behaviour over which special behaviour can be built.

Actor Director example

No comments:

Post a Comment