How can i choose Abstract class or Interface..? [duplicate]
Possible Duplicates:
Interface vs Base class Abstract classes vs Interfaces
How can we take decision about when we have to use Interface and when Abstract Class..??
Any idea..??
Thank in advance!
Do you want to provide a shared implementation of a method?
Use an abstract class.
Do you simply want to provide a contract that specifies what external functionality an object must provide?
Use an interface.
My rule of thumb is: Use an abstract class when there is shared code, otherwise use an interface.
If you plan to have the same implementation of part of your methods and properties then use abstract class, if you want just to hold the same members in all classes, but with a diffrent implementation for all of them then use interface.
In other words use interface if some of your derived class methods should be exacaly the same in each derived class, otherwise use interface.
Have a look at this interesting article that will help you understand the differences between Interfaces and Abstract Classes on CodeProject.
精彩评论