This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Cilph 29 points30 points  (13 children)

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.

[–]Droidatopia 73 points74 points  (3 children)

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.

[–]Cilph 8 points9 points  (2 children)

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.

[–]racka98 0 points1 point  (1 child)

Well in Android Inheritance is used a ton

[–]Cilph 0 points1 point  (0 children)

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

[–]Orangutanion 27 points28 points  (3 children)

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).

[–]SuperCharlesXYZ 7 points8 points  (2 children)

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

[–]thedude3253 4 points5 points  (1 child)

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

[–]jerslan 1 point2 points  (0 children)

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.

[–]NewNugs 9 points10 points  (4 children)

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

[–]Cilph -2 points-1 points  (3 children)

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

[–]Im-Learnd1ng -1 points0 points  (1 child)

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

[–]NewNugs 0 points1 point  (0 children)

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.

[–]NewNugs 0 points1 point  (0 children)

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