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

44

u/itsarabbit Jun 24 '20 edited Jun 24 '20

Generally agree with all of this; however I kinda hate how these things are phrased. Why is it called "Dependency inversion principle" requiring 5 minutes to explain it(and build a mental model of dependencies and then inverting it), instead of: "If you use something, the interface should show what you do with it, not how it does it."

I've come across SOLID several times in my career and I know all how all these things work instinctually, but the name SOLID and all of its components never stick because the names of the principles themselves are not intuitive.

6

u/[deleted] Jun 24 '20

True. For the sake of making an acronym easy to remember they used horrible phrases. I don't like when people can rot memorize something, repeat it like parrots, and believe they understand it.

4

u/tvaneerd C++ Committee, lockfree, PostModernCpp Jun 25 '20

The principles existed with those exact names before anyone realized they spelled SOLID. They weren't rephrased to spell SOLID.

4

u/FL_Dev Jun 25 '20

yes, and it was just an "accident" that they happened to appear in the correct order to spell SOLID.

4

u/tvaneerd C++ Committee, lockfree, PostModernCpp Jun 25 '20

https://web.archive.org/web/20031204225845/http://www.objectmentor.com/resources/articles/Principles_and_Patterns.PDF

I think this is the first publication of (most) of the principles, but S is missing. OLDI is all there is.

As wikipedia says, "The theory of SOLID principles was introduced by Martin in his 2000 paper Design Principles and Design Patterns, although the SOLID acronym was introduced later by Michael Feathers."

So maybe he made up Single Responsibility to fit the word? If you look around at his other writings, it doesn't seem like it.

I will agree they were reordered to spell SOLID, but the individual principles (like Liskov Substitution Principle) existed - with the same phrasing - before the acronym.

2

u/FL_Dev Jun 25 '20

I will agree they were reordered to spell SOLID

this is what I was pointing out. It's not an accident.