Saturday, February 16, 2013

What is the difference between an interface and an abstract class ?
Interface    Abstract Class
You cannot use access specifiers with members of an interface. All interface members are implicitly public and cannot have any other access specifier.    Members of abstract class can have all access specifiers except private i.e. they can be internal, public, protected and protected internal but not private.
All the members of an interface are implicitly abstract (although you cannot explicitly use abstract keyword because it not allowed to use access specifiers in interface).    An abstract class can have non-abstract members.
Interface cannot have static members.    Abstract classes can have non-abstract static members.
A class can inherit one or more interfaces.     A class can inherit from only one abstract (or non-abstract ) class.
Modifying an interface results in breaking the existing clients. This is because clients must implement all interface members, and interface members are only declarations , no code or values are allowed.    Not all modifications in an abstract class break existing clients. E.g. adding a new non-abstract method to the base abstract class will not break existing clients.
Interfaces CANNOT have constructors and destructors.    Constructors and destructors ARE ALLOWED in abstract classes.
The abstract class constructors cannot be abstract or private.
Interface    Abstract Class
You cannot use access specifiers with members of an interface. All interface members are implicitly public and cannot have any other access specifier.    Members of abstract class can have all access specifiers except private i.e. they can be internal, public, protected and protected internal but not private.
All the members of an interface are implicitly abstract (although you cannot explicitly use abstract keyword because it not allowed to use access specifiers in interface).    An abstract class can have non-abstract members.
Interface cannot have static members.    Abstract classes can have non-abstract static members.
A class can inherit one or more interfaces.     A class can inherit from only one abstract (or non-abstract ) class.
Modifying an interface results in breaking the existing clients. This is because clients must implement all interface members, and interface members are only declarations , no code or values are allowed.    Not all modifications in an abstract class break existing clients. E.g. adding a new non-abstract method to the base abstract class will not break existing clients.
Interfaces CANNOT have constructors and destructors.    Constructors and destructors ARE ALLOWED in abstract classes.
The abstract class constructors cannot be abstract or private.
   
Interface    Abstract Class
You cannot use access specifiers with members of an interface. All interface members are implicitly public and cannot have any other access specifier.    Members of abstract class can have all access specifiers except private i.e. they can be internal, public, protected and protected internal but not private.
All the members of an interface are implicitly abstract (although you cannot explicitly use abstract keyword because it not allowed to use access specifiers in interface).    An abstract class can have non-abstract members.
Interface cannot have static members.    Abstract classes can have non-abstract static members.
A class can inherit one or more interfaces.     A class can inherit from only one abstract (or non-abstract ) class.
Modifying an interface results in breaking the existing clients. This is because clients must implement all interface members, and interface members are only declarations , no code or values are allowed.    Not all modifications in an abstract class break existing clients. E.g. adding a new non-abstract method to the base abstract class will not break existing clients.
Interfaces CANNOT have constructors and destructors.    Constructors and destructors ARE ALLOWED in abstract classes.
The abstract class constructors cannot be abstract or private.
   

No comments:

Post a Comment

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...