When to use Abstract class and When to use an Interface in .NET with an Example? I have not been able to find a definitve answer for the same any help on the same would be very helpful
-
http://stackoverflow.com/questions/761194/interface-vs-abstract-class-general-oo – Brandon Moretz Jun 26 '13 at 13:13
1 Answers
I defer to interfaces when I want to define a contract but in no circumstances provide any implementation. Once you go down the route of abstract classes with boiler-plate functionality, you're already going down the route of implementation.
That said, sometimes it makes sense to do both. This is where the designer of an API defines an interface (the contract), and then an abstract base-class with some boiler-plate functionality that takes some of the common legwork out of implementing the interface. This is a common idiom.
Interfaces are great for defining a contract with absolutely no reliance on any implementation and abstract base classes are great for providing some default behaviour, meaning the developer doesn't have to spend ages writing the same thing over and over again.

- 38,257
- 10
- 78
- 128