What is the main importance of Interface and also abstract class In .NET

Posted by Kasani007 under ASP.NET on 8/6/2014 | Points: 10 | Views : 1706 | Status : [Member] | Replies : 2
What is the main importance(main purpose) of Interface and also abstract class In .NET ?




Responses

Posted by: kgovindarao523-21772 on: 8/6/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change.
Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.

If you are designing small, concise bits of functionality, use interfaces.
If you are designing large functional units, use an abstract class.

If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.
Please Mark as answer if this post redirects you to your answer

Thank you,
Govind

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

Posted by: Manimaddu on: 8/11/2014 [Member] Starter | Points: 25

Up
0
Down
Hi..
The main difference is that if you use an abstract class and then write generalized code against that abstract class, you're forcing all concrete instances to belong to single hierarchical lineage of class.

If you generalize to an interface, you're writing code that does not enforce a single class hierarchy or any class hierarchy for that matter.

Since abstract classes and interfaces aren't mutually exclusive, you can use both. Use an interface to enforce consistency of method signatures and then abstract classes to enforce a particular lineage of class hierarchy.

Thanks & Regards,
Mani Kumar

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

Login to post response