this post was submitted on 02 Sep 2024
884 points (99.2% liked)

Programmer Humor

32041 readers
936 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

Incase it doesn't show up:

you are viewing a single comment's thread
view the rest of the comments
[–] magic_lobster_party@fedia.io 1 points 2 weeks ago (24 children)

So things like abstract classes are mostly absent from my codebase.

I believe the consensus nowadays is that abstract classes should be avoided like the plague even in languages like Java and C#.

[–] void_star@lemmy.world 13 points 2 weeks ago (23 children)

I have not heard this consensus. Definitely inheritance where the base class holds data or multiple inheritance, but I thought abstract was still ok. Why is it bad?

[–] magic_lobster_party@fedia.io 6 points 2 weeks ago (22 children)

In 99% of the cases, inheritance can easily be replaced with composition and/or interfaces. Abstract classes tend to cause hard dependencies that are tough to work with.

I’m not sure why you would use abstract classes without data. Just use interfaces.

[–] Zangoose@lemmy.world 1 points 2 weeks ago (1 children)

The way I was taught was that you usually start off with only an interface and then implementing classes, and then once you have multiple similar implementations it could then make sense to move the common logic into an abstract class that doesn't get exposed outside of the package

[–] magic_lobster_party@fedia.io 2 points 2 weeks ago

I usually break it out using composition if that’s ever needed. Either by wrapping around all the implementations, or as a separate component that is injected into each implementation.

load more comments (20 replies)
load more comments (20 replies)
load more comments (20 replies)