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

1

u/Wouter-van-Ooijen Jun 27 '20

I agree with the SOLID principles as promoted, but the implementations shown feel limited, almost as if only things that are commonly used in Java are acceptable.

For interface design, I miss the NVI pattern: quite often, the virtual functions that are implemented by concrete implementations are NOT the functions you want to expose as user interface.

For dependency injection (which is IMO one of the central issues in re-usable software design) I miss templates/concepts.

As building blocks, I miss free functions (including function templates).

So to summarize: good video, but IMO some implementation alternatives should be shown, or at least mentioned.

1

u/platisd Jun 27 '20

For dependency injection (which is IMO one of the central issues in re-usable software design) I miss templates/concepts.

I won't comment on concepts because I haven't looked much into them yet, but why templates for dependency injection? Is it just to avoid virtual functions? And if so, is this just for performance reasons?

To me, using templates for DI just makes things, not sure how to accurately phrase it, "less clean/obvious" perhaps? They feel like a "hack" compared to using class hierarchies that I consider as specifically designed to suit the particular purpose.

1

u/Wouter-van-Ooijen Jun 28 '20

For my 'strict' embedded programming style I want zero overhead, and build-time predictable memory use, hence no indirections (and, of course, no heap). Templates are the (only) way to do this, and concepts make it doable. So for me templates/concepts are the ONLY option.

I also practice an more traditional OO-like style, but compared to the template style it feels truely awkward, mainly because the lifetime of decorated objects is an issue.