3 ms·
The way I'm thinking about it (just a different expression of the exact same thought) is that inheritance as a means to share code is bad, while inheritance as
by jupp0r 3y ago
The way I'm thinking about it (just a different expression of the exact same thought) is that inheritance as a means to share code is bad, while inheritance as a means to leverage polymorphism is good. Polymorphic classes can still share code, but this should be done using composition.
- rramadass 3y ago> inheritance as a means to share code is bad, Not necessarily; if they are strongly coupled related concepts within the same module then it is perfectly fine (eg. private inheritance in C++). Here you are basically structuring for code reuse and not is-a relationship. >inheritance as a means to leverage polymorphism is good. This is the "standard" idea of inheritance i.e. sub-typing using Liskov Substitution Principle. > Polymorphic classes can still share code, but this should be done using composition. Not necessarily as a combination of the above two should make clear.