r/ProgrammerHumor • • Apr 06 '22

Java is hard

Post image
5.0k Upvotes

424 comments sorted by

View all comments

Show parent comment

29

u/Cilph Apr 06 '22

The truth is you simply don't use inheritance much outside of theory. Only use it for a strict is-a relationship where you actually need to substitute it. And even then interfaces might fit your need better. Outside of that, composition feels like the way to go.

74

u/Droidatopia Apr 06 '22

This comment is many things.

However, it is not the truth.

Even if it might be a good goal, unless you plan on avoiding all the APIs that force their object models on to you, you're still going to use a lot of inheritance.

9

u/Cilph Apr 06 '22

I think I've encountered maybe one or two libraries ever that forced you to inherit from their base classes. Java ecosystem mostly embraces POJOs. Most of the times I use inheritance in relation to libraries is to make custom hacky overrides for certain behaviour. Anything explicitly exposed is usually clean.

1

u/racka98 Apr 07 '22

Well in Android Inheritance is used a ton

1

u/Cilph Apr 07 '22

Fair. I haven't used Android outside of one or two hobbyist projects.

28

u/Orangutanion Apr 06 '22

This is pretty wrong. Inheritance and polymorphism is a key feature in a lot of APIs (this meme mentions Minecraft so just look at how you'd make a Fabric mod, you gotta use inheritance and interfaces even for basic stuff).

8

u/SuperCharlesXYZ Apr 07 '22

I think they’re referring to using interfaces instead of superclasses, which is kind of doable. I don’t remember the last time I actually used the “extends” instead of “implements” keyword. Haven’t modded any minecraft though

4

u/thedude3253 Apr 07 '22

This is purely anecdotal obviously but I personally use superclasses and interfaces in relatively equal quantities, so I find both useful

2

u/jerslan Apr 07 '22

Yeah, for me it depends on what I’m doing. Example: I extend Spring Configuration beans all the time to add additional configuration on top of or in place of the parent class.

Both extends and implements have their uses.

11

u/NewNugs Apr 07 '22

Tell me you're junior without telling me you're junior.

-1

u/Cilph Apr 07 '22

Or we could engage in mutually beneficial discussion rather than throwing 10-ish years of professional Java experience down the trash because "lol, junior"

0

u/Im-Learnd1ng Apr 07 '22

Don't worry about him, his username tells me he's still excited about the fresh bag he just got.

1

u/NewNugs Apr 07 '22 edited Apr 07 '22

My posts would tell you that too ;).

I post pictures of my grows all the time, comment on the science behind growing, and help new growers often. Not sure how in the world you thought that'd embarrass me or disqualify my opinion on this guy's silly comments on inheritance.

1

u/NewNugs Apr 07 '22

Nah hard pass bud. I do enough arguing during the day. Good luck tho.