Sometimes I wonder that we do have interfaces and abstract classes for two different reasons:
If you just want multiple implementations for design purposes and something to code against at the development time then interface is the best choice that we have got.
If you want to reuse the code then we might go for the abstract classes.
BUT, I have seen something that is neither.
In some designs, it is like this Interface > BaseClass > Child
class.
So basically a base class implements all the methods and then the child class inherits the definition from it. Why can we not use an abstract class instead of this setup? Or this is a flawed setup?
The most simple reasining is if an object has a IS-A relation then use an (abstract) base class. Like a horse IS an animal.
If there is a CAN relation, then think about interfaces, like if a Duck CAN fly, use IFlying as interface for a duck that can fly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With