What is the difference between an interface and abstract class?

Interface and Abstraction cannot be instantiated. Abstract class is also like interface until abstract class is implemented.  I have explained in detail difference between an interface and abstract class.

Abstract Interface Class

  1. Abstract class requires virtual method for its implementation in common behavior. Interface class does not require it.
  2. Abstract can’t be instantiated. Interface class also can’t be instantiated.
  3.  Abstract class is idle until we can’t call from the derived class. Interface class also has the same feature it’s not in use until we call it from sub classes.
  4. Interface class is slower than abstract class. Abstraction class is much faster than interface class.
  5. Interface class requires its implementation in sub classes so when we make any changes in interface class we have to track down all implantation & carefully we have to make changes in the classes otherwise compiler will throw error. Abstraction class has default implementation so it does not require tracking down all classes correspondingly. 
  6. Fields & constants cannot be defined in interface class. In abstraction class we can define constants & fields.
  7. An interface class cannot have access modifiers subs, functions; methods have by default public access modifiers.
  8. An interface class has not provided any code only can just provide signatures.  Abstraction class has the ability to provide the implementation and have also the ability to override its methods, functions etc.
  9. An interface class can be implemented when units of functions are small. Abstraction class can be implemented when units of functions are very big. This implementation application becomes more neat and clean with no complexity of code.
An Interface and Abstraction classes are implemented in the application to make code more robust, clean and flexible.

No comments:

Post a Comment