Thursday, October 6, 2011

Abstract Vs Interface




Abstract

Interface
Abstract class having method declaration as well as method method definition.
 Interface having method declaration only.
Abstract class are known as partial abstract class
Interface is known as fully abstract class
Abstract class features we have to inherit to the child class
Interface features we have to implement in the child classes.
Abstract class support access specifiers
Interface doesn't support access specifiers
We can write constructor in abstract class
we can't write constructor in interface

More....
  • The abstract class allows concrete methods (methods that have implementation) but interface doesn’t not.
  •  A class can inherit from only one class, but can implement any number of interfaces.
  •  Interface doesn’t allow variables/constants to be declared but abstract class allows for declaration of variables and constants
More...

Abstract Class vs. Interface

1.      An abstract class may contain complete or incomplete methods. Interfaces can contain only the signature of a method but no body. Thus an abstract class can implement methods but an interface cannot implement methods.
 
2.      An abstract class can contain fields, constructors, or destructors and implement properties. An interface cannot contain fields, constructors, or destructors and it has only the property's signature but no implementation 
 
3.      An abstract class cannot support multiple inheritances, but an interface can support multiple inheritances. Thus a class may inherit several interfaces but only one abstract class.
 
4.     A class implementing an interface has to implement all the methods of the interface, but the same is not required in the case of an abstract Class.  
 
5.      Various access modifiers such as abstract, protected, internal, public, virtual, etc. are useful in abstract Classes but not in interfaces.
 
6.      Abstract classes are faster than interfaces.



No comments:

Post a Comment

Abstract Factory Vs Factory Method

Abstract Factory Provides an interface for creating families of related or dependent objects without specifying their concrete classes ...