difference between abstract and interface

Posted by Shanky11 under ASP.NET on 11/27/2012 | Points: 10 | Views : 1875 | Status : [Member] | Replies : 2
where to use abstract and interface in .net.please provide the deetails




Responses

Posted by: Saratvaddilli on: 11/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Abstract and Interface:
we often confuse whats the difference between Abstract classes and Interfaces both act like a templates
In Abstract :
we can declare a method as well as some variables
In Interfaces:
we can only declare methods

for more in depth go through this link
http://www.codeproject.com/Articles/11155/Abstract-Class-versus-Interface

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 11/27/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Use an abstract class
-When creating a class library which will be widely distributed or reused-especially to clients, use an abstract class in preference to an interface; because, it simplifies versioning. This is the practice used by the Microsoft team which developed the Base Class Library. ( COM was designed around interfaces.)
-Use an abstract class to define a common base class for a family of types.
-Use an abstract class to provide default behavior.
-Subclass only a base class in a hierarchy to which the class logically belongs.

Use an interface
-When creating a standalone project which can be changed at will, use an interface in preference to an abstract class; because, it offers more design flexibility.
-Use interfaces to introduce polymorphic behavior without subclassing and to model multiple inheritance-allowing a specific type to support numerous behaviors.
-Use an interface to design a polymorphic hierarchy for value types.
-Use an interface when an immutable contract is really intended.
-A well-designed interface defines a very specific range of functionality. Split up interfaces that contain unrelated functionality.

Refer this url
http://mindprod.com/jgloss/interfacevsabstract.html

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response