891

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 -2 points 10 months ago

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 10 months ago

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 7 points 10 months ago

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.

[-] void_star@lemmy.world 3 points 10 months ago

Perhaps we have a terminology mismatch, I tend to use abstract class and interface interchangeably. I’m not sure it’s possible to define a class interface in c++ without using inheritance, what kind of interface are you referring to that doesn’t use inheritance?

[-] jorp@lemmy.world 1 points 10 months ago* (last edited 10 months ago)

I don't think it's what the person you're replying to meant, but template metaprogramming in modern c++ allows the use of "duck typing" aka "static polymorphism" where you can code against an interface without requiring inheritance.

[-] void_star@lemmy.world 2 points 10 months ago

Typically this is done with CRTP which does require inheritance. But I agree, you can do some meta programming or use concepts which can enforce interfaces in a different way. But back to the original comment that interfaces via inheritance are objectively bad, I don’t think there’s any consensus that this is true. And pure virtual interfaces and CRTP are both common use cases of inheritance in modern C++ codebases and are generally considered good design patterns.

load more comments (19 replies)
load more comments (19 replies)
load more comments (19 replies)
this post was submitted on 02 Sep 2024
891 points (99.1% liked)

Programmer Humor

37012 readers
179 users here now

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

Rules:

founded 5 years ago
MODERATORS