Use namespaces instead of classes

C++ namespaces are an under-valued aspect of the language. In fact, I will go even further by saying that most member functions within classes should in fact be functions within namespaces instead. Classes are way over-rated IMHO.

Structuring your code this way has a number of key benefits. Firstly, it forces you to distinguish between the real member functions that are extremely tightly coupled to the object and those that are more loosely coupled. The latter can be taken out of the class, put into a separate file+namespace and then and reused in other contexts.

Separating out non-essential functions from a class makes the class itself smaller and easier to maintain. Since the removed function is placed into its own file, it's also more easily understood and maintained.

To avoid tight coupling between the removed function and its original class, you can use a function template parameter and pass in a reference to the class. This way you don't even need to include the orignal class header and can use the removed function on other similar classes provided they have the same interface. This is a more flexible fine-grained approach than the traditional monolithic everything in one class approach.

It also leaves the class open for extension in a way that adding member functions to a class will never equal. To add functionality, you'll hardly ever need to touch the original class. Simply define a new function within the objects namespace and pass in a reference instead.

It seems like on every new feature of C++, everyone goes way overboard. Firstly, it was inheritance. Libraries were appearing with huge inheritance heirarchies. In fact some developers were inheriting completely unrelated functionality - which is not what inheritance was ever intended to be used for. Inheritance is a form of coupling, and from software engineering first principles is bad and should be minimised. Eventually, developers started to see the light and found out the hard way that such deep inheritance can be error-prone and difficult to maintain.

Then came the template brigade. Suddenly inheritance was bad and just about everything became a template instead. I give you exhibit a), the standard template library. This is a classic example of templates gone mad. Everything was shoehorned into one mould, even if it didn't fit. This movement is still active and vibrant today, as is evident by the existance of the boost libraries. Just because it can be a parameter, does not mean everything should be parameterised!

Don't get me wrong, I love all these features of C++, but they should be used sparingly and in the right context. Their use and pros-and-cons should be weighed up carefully against several other alternatives. This is something experienced developers learn over time. Newbies will not see or understand this when they first begin to code in C++.