I don't like the idea to be limited to one paradigm either. I use them as I see fit. However, to these kind of things, classes are best IMHO. All functionality for an object to be grouped inside its object and not broken out.
Why is it so difficult to learn C++ and not VB or Java (unsure about this one) or such languages, I wonder? Because everything is neatly organized into one place.
If a programmer has to rely on algorithms to get things done (and I mean simple tasks), or go browse through a namespace that's not named in the docs, things DO get harder.
Difficulty is what I try to avoid. No wonder C++ is difficult to learn.
And some don't seem to understand my point either...
Classes, like functions, can be extended. It's your job to make sure they can be. They should be. Otherwise you did something wrong.
One class should be one thing. Don't add everything into it. But a string class should have certain things, such as ToLower/ToUpper, which the standard library seem to lack.
Classes can grow just as free functions can grow. Now, the problem is to find a way to make it possible for the classes to grow similar to free functions.
I don't think I'd use static members, though. They would appear inside the class namespace. I'd rather make them free and move them into the Strings namespace... Neatly organized.
Perhaps another question is: how do I break out the implementation from the definition of a specialized template?
Instead of:
Code:
template<> class StrConversion<wchar_t>
{
public:
CStringExA ToANSI() { /*... */ }
private:
virtual const wchar_t* GetData() = 0;
};
This:
Code:
template<> class StrConversion<wchar_t>
{
public:
CStringExA ToANSI();
private:
virtual const wchar_t* GetData() = 0;
};
template<> CStringExA strConversion<wchar_t>::ToANSI() { /* ... */ }