Timeline for When to use abstract classes instead of interfaces with extension methods in C#?
Current License: CC BY-SA 2.5
5 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 8, 2016 at 8:17 | comment | added | sara | There is no rule that says that if it's grammatically and semantically meaningful to say "B is an A" then A must be an abstract class. You should prefer interfaces until you really can't avoid the class. Sharing code can be done via composition of interfaces, etc. It makes it easier to avoid painting oneself into a corner with weird inheritance trees. | |
| Jun 15, 2011 at 11:33 | comment | added | Dainius | if you have abstract methods, than you have abstract class. And abstract methods you have when there is no value for implementing them (like "go" for animal). And of course sometimes you don't want to allow objects of some general class, than you make it abstract. | |
| Feb 1, 2011 at 21:05 | comment | added | Dario |
@Gulshan: If it does - for some reason - not make sense to actually create an instance of the base class. You can "create" a Chihuahua or a white shark, but you cannot create an animal without further specialization - thus you would make Animal abstract. This enables you to write abstract functions to be specialized by the derived classes. Or more in programming terms - it does probably make no sense to create a UserControl, but as a Button is a UserControl, so we have the same kind of class/baseclass relationship.
|
|
| Jan 31, 2011 at 12:28 | comment | added | Gulshan | When would you choose to keep a base class abstract? | |
| Jan 31, 2011 at 12:13 | history | answered | Dario | CC BY-SA 2.5 |