logoalt Hacker News

crabmusket • 11/20/2024 • 4 replies • view on HN

Mainstream OOP languages (looking at you Java) have failed to make composition as convenient as inheritance.


Replies

flakes • 11/20/2024

The common toolkits today (spring boot, google guice, etc) are much more focused on composition over inheritance, by injecting arguments and implementing pure interfaces rather than extending base classes. Older legacy Java frameworks and bad teachers are more at fault than the Java language itself IMO.

➕ show 1 reply
_old_dude_ • 11/20/2024

Very true, in Java, at least in the last 20 years, inheritance is de-facto deprecated, all new bits and bolts like enums, annotations, lambdas or records do not support inheritance.

So you have to use composition.

yxhuvud • 11/20/2024

How is composition inconvenient?

➕ show 1 reply
watwut • 11/20/2024

How is composition in Java inconvenient?