Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
What are the Advantages Of Using Abstract class and Interface ?

Regards
Balamurugan
Posted
Updated 3-Feb-14 1:35am
v2
Comments
BillWoodruff 3-Feb-14 22:49pm    
Using either one, or both, of Interfaces and Abstract Classes, may, or may not, have any advantages depending on what you are doing.

I suggest you get a good basic book on C# programming and OOP. I'd recommend Jesse Liberty's "Learning C Sharp" series books from O'Reilly.

 
Share this answer
 
We can't define fields in an interface but can define fields in an abstract class.
The interface has a signature of methods but an abstract class can contain both types of methods; these have a signature or an implementation.
Interface members are by default public and can't use an access specifier for them but in an abstract class we can define an access specifier for each member.
An interface is slow because it needs to find the actual method in the corresponding classes. But an abstract class is fast.
We can inherit from multiple interfaces for a single class but can't inherit multiple abstract classes.


Here's a quote from "The Complete Reference C# 2.0" by Herbert Schildt that :

"When you can fully describe the concept in terms of "what it does" without needing to specify any of "how it does it", then you should use an interface. If you need to include some implementation details, then you will need to represent your concept in an abstract class."

http://social.msdn.microsoft.com/Forums/en-US/8ad621b8-a915-4d7e-89c3-5dbbc47202fd/whats-the-difference-between-abstract-classes-and-interfaces?forum=csharplanguage[^]
 
Share this answer
 
v3
Comments
Bala1989 3-Feb-14 7:52am    
In normal class also we can inheit nd then y we r using abstract class.
Sandeep Singh Shekhawat 3-Feb-14 7:57am    
The abstract modifier indicates that the thing being modified has a missing or incomplete implementation. The classes that can't be initialized are called abstract classes. Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes. The members of the class don't have an implementation in a class with an abstract modifier. The abstract modifier can be used with classes, methods, properties, indexers, and events. Members marked as abstract, or included in an abstract class, must be implemented by classes that derive from the abstract class.
Interfaces and Abstract classes allow you to plan for evolution i.e. these standard features in OOP based programming languages give you an option to enhance your program at a later stage when customer demands for more features.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900