Click here to Skip to main content
15,891,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Which should i need to use ...My requirement gets change in Future

Abstract Class or Interface Class...Which will you decide


This is an interview question asked by one of the interviewee..

Answer pls..
Posted
Comments
Mehdi Gholam 6-Sep-14 3:22am    
It depends on what you are doing and how you are doing it.


[^]
 
Share this answer
 
Short answer: Interfaces are for architects, Abstract Classes are for coders.
Long answer: it really depends on the scenario (and on the lack of multiple inheritance of C#). Check out a good OOP book in order to tell the difference.
 
Share this answer
 
It's not a "either / or" situation: they are very different beasties.
An abstract class is an "almost complete" class that requires the derived class to "fill in the blanks" but allows you to provide code which is common to all derived classes.
An Interface doesn't: it allows you to specify a contract which the implementing class must complete, but which can provide no code at all.

You can derive from a class and implement an unspecified number of interfaces at the same time, but you can only derive from a single abstract class.

It's like the difference between a Fruit (abstract class) and IDrive (Interface) - the former allows you to derive Apple and Pear classes, while the latter allows you to use a car to get from A to B. A Fruit exists; IDrive is a process that you can't hold in your hand.
 
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