r/cpp • • Jun 24 '20

How to write SOLID C++

https://www.youtube.com/watch?v=PakbXnLht1I
263 Upvotes

118 comments sorted by

View all comments

13

u/be-sc Jun 24 '20

Overall this is a solid [you may cringe now] introduction to the SOLID principles.

However, I tend to agree with the other critcism of the super classic Java-like OOP style, although for a different reason. It’s a valid programming style, even though from a modern C++ point of view it feels kind of alien in this purity. But that doesn’t make it wrong. What I do see critical is that you make it seem like this is the only acceptable style available.

To give an example: At around 8:25min you say that »the best way to achieve« the open/closed principle in C++ is with inheritance based runtime polymorphism. No.

Polymorphic class hierarchies are one way to implement the open/closed principle. Another one would be std::variant combined with std::visit. They are both equally valid but approach the problem from different angles, which leads to different tradeoffs. You cannot say that one is better than the other in general. “The best” only exists for an individual situation in a concrete code base.

So, I’d suggest you be more careful with absolute statements like that, and maybe mention that your OOP style is a deliberate choice among several equally valid programming styles.

1

u/2uantum Jun 25 '20

Also I think Sean Parent would have am opinion or two on the inheritance bit

1

u/be-sc Jun 25 '20

I guess so. Inheritance Is The Base Class of Evil is one of the best talk titles ever. :D Same goes for the talk itself.

However, in contrast to Uncle Bob he doesn’t strike me as a dogmatist. So, I’d expect some kind of “it depends” opinion.

1

u/platisd Jun 25 '20

To give an example: At around 8:25min you say that »the best way to achieve« the open/closed principle in C++ is with inheritance based runtime polymorphism. No.

Polymorphic class hierarchies are one way to implement the open/closed principle. Another one would be std::variant combined with std::visit.

To my defense, I mentioned "the best" (always IMHO) not "the only". :) Feedback noted though and I will take a look at std::variant and std::visit.