logoalt Hacker News

carmackfanlast Saturday at 1:37 AM1 replyview on HN

You don't need to precisely know about the future to know that inheritance isn't for sharing behavior. Unfortunate it's not really taught properly.


Replies

ryaolast Saturday at 11:02 PM

That is easy to say in hindsight when given the example. It is not so easy to see in advance. After all, OOP’s proponents say that OOP makes everything better. You never hear them saying “don’t use OOP here”.

https://duckduckgo.com/?q=oop+inheritance+behavior

I doubt you would find a single result in the top 10 saying not to do this and many will seem to encourage it. One of the results says:

> Inheritance is frequently used to integrate your code with library code

A much younger version of myself said: Daemonizing should be a library function. Let’s use inheritance to do that.

Saying it is not really taught properly is avoiding the reality that you just can’t teach it properly. Knowing for certain when it will not cause problems requires knowing the future.