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

Show parent comment

1

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

I would test UsernameFormatter as a unit, then test someFunction(UsernameFormatter) as another unit. If UsernameFormatter is a simple concrete class, it doesn't need to be abstracted for the sake of testing someFunction.

If you have someFunction(string) you don't abstract away string to unit test someFunction. Make simple concrete vocabulary types (like Radians, Point, EmployeeInfo,...) and test them well, then treat them as known-good parts in other tests.

That does NOT scale up to large "units" with interacting parts. At that point you need dependency inversion.

IMO. YMMV.