3 ms·
> Nobody said that inheritance must be polymorphic. The derived object has to be substitutable for the base object. If not, then you don't have the late bindin
by kazinator 4y ago
> Nobody said that inheritance must be polymorphic.
The derived object has to be substitutable for the base object. If not, then you don't have the late binding needed for OOP.
I would say that the third pillar ther should be "multiple inheritance".
Single inheritance is fake/garbage inheritance, not suitable for full blown OOP.
If you just have single inheritance, and you've already committed a class to an inheritance base (out of some necessity), then you're screwed if you suddenly need an object of that type to be an "instance of" something else.
- kaba0 4y agoMultiple inheritance has grades. It’s perfectly fine to have single class inheritance and multiple interface one for example.
- kazinator 4y agoYes. If you don't have it, that's an F grade. Ruby modules get a D, and Java interfaces a C-. C++ gets a D- with its base classes having to be declared "virtual" nonsense in order that your object isn't a Duck in four different ways due to diamonds in the inheritance lattice.
- bheadmaster 4y ago> The derived object has to be substitutable for the base object That's polymorphism, and isn't part of the definition of inheritance. Otherwise, inheritance and polymorphism wouldn't be separate concepts.