Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Do they? I rarely see people using it directly and I think this is fine


Same here. For me, implementation inheritance is a code smell. But I rarely see it.


Most of us have no contact with Java. But Java offers little else than inheritance to use to organize a system, so Java coders use it for everything. They are not exactly wrong, except in using Java at all. But sometimes is all that is allowed.


This is much less true for modern Java than it used to be, with records, pattern matching, sealed classes, etc.

The trick though is you actually have to use modern Java, which means you need to both be on the right version of Java, and have developers that understand the value/power of these newer constructs. Which is surprisingly rare for a programmer that self-identifiers as a Java programmer.


java offers composition, like pretty much all programming languages

if you have a person class and you have students and teachers

the correct thing to to is NOT to make student and teacher inherit from person

it's to make student and teacher have a person attribute + the other attributes that constitute a student and teacher respectively


"correct" is certainly not the right way to put that. Inheritance and composition here are both fully valid methods for modeling the relationship, and the decision to use either should be dependent on how the models are being used and the expectation for future extension.


By "correct" here you only mean fashionable. Either approach works. Each has its merits and its costs.

Any big enough system will have parts that are most sensibly built object-oriented, and other parts that are more reasonably functional, plus anything else you can think of.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: