logoalt Hacker News

crabmusketlast Wednesday at 5:52 AM4 repliesview on HN

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


Replies

flakeslast Wednesday at 6:34 AM

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_last Wednesday at 11:08 AM

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.

yxhuvudlast Wednesday at 9:57 AM

How is composition inconvenient?

show 1 reply
watwutlast Wednesday at 12:15 PM

How is composition in Java inconvenient?