When should I use an interface and when should I use a base class?
Should it always be an interface if I don\'t want to actually define a base implementation of the
It depends on your requirements. If IPet is simple enough, I would prefer to implement that. Otherwise, if PetBase implements a ton of functionality you don't want to duplicate, then have at it.
The downside to implementing a base class is the requirement to override
(or new
) existing methods. This makes them virtual methods which means you have to be careful about how you use the object instance.
Lastly, the single inheritance of .NET kills me. A naive example: Say you're making a user control, so you inherit UserControl
. But, now you're locked out of also inheriting PetBase
. This forces you to reorganize, such as to make a PetBase
class member, instead.