Tuesday, June 29, 2010

What Is The Different Between Abstract Class And Interface

Abstract Base Vs Interface

Abstract class:
An Abstract class without any implementation just looks like an Interface; however there are lot of differences than similarities between an Abstract class and an Interface.
  • We cannot make instance of abstract class.
  • An abstract class is only to be sub-classed (inherited from).
  • In other words, it only allows other classes to inherit from it but cannot be instantiated.
The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, t is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.

Interface concept:
An interface is not a class.
An interface has no implementation; it only has the signature.
It just the definition of the methods without the body.

Similarity between Abstract class and Interface:
They act as a contract that is used to define hierarchies for all their subclasses.

Different:
A class can implement more than one interface but can only inherit from one abstract class.
Since C# doesn't support multiple inheritance, interfaces are used to implement multiple inheritance.

Sample Code Download: AbstractBase_Vs_Interface.zip

No comments:

Image Understanding (IU)

Throughout these years, the growth of digital media collections has been accelerating, particularly in still images. These artifacts repre...