What do you use if you want all methods and properties to be implemented
An interface or abstract class will do what you want. In an abstract class, if a is method
marked as abstract
, then it must be implemented in the derived class. The question really comes down to what you should be using. Interface or abstract class.
The quick answer (and I mean the quick and the dirty) is that you should use an interface when trying to set up contractual behavior between classes. You should use an abstract class when the collection of the derived class has some common behavior.
source to share
The interface ensures that the class has method stubs for all methods, but they may not be implemented and may throw NotImplementedExceptions.
The best way to ensure that all methods are implemented is to use unit tests, where you check if the methods actually do what they want them to do.
source to share