Re:Object-oriented Programming with ANSI-C (1993) [pdf]
by jupp0r on Wednesday June 21, 2023 @11:17PM
(#36427619)
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.
[ Parent
| on HN ]
Re:Object-oriented Programming with ANSI-C (1993) [pdf]
by rramadass on Thursday June 22, 2023 @02:36AM
(#36428689)
> 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.