I don't entirely agree that utility classes are evil.
While a utility class may violate OO principals in some ways, they aren't always bad.
For example, imagine you want a function that will clean a string of all substrings matching value x
.
stl c++ (as of now) doesn't directly support this.
You could create a polymorphic extension of std::string
.
But the problem is, do you really want EVERY string you use in your project to be your extended string class?
There are times when OO doesn't really make sense, and this is one of them. We want our program to be compatible with other programs, so we will stick with std::string
and create a class StringUtil_
(or something).
I'd say it's best if you stick with one util per class. I'd say it's silly to have one util for all classes or many utils for one class.