A recent question made me rethink that all helper classes are anti-pattern.
asawyer pointed out several links in the comments on this question: The classes helper is anti-pattern .
While these links detail how helperclasses clash with well-known principles, some things are still unclear to me.
For example, "Do not repeat yourself." How can you do this without creating your assistant? I thought you could get a specific type and provide some functions for it. But I believe that this is not practical all the time.
Let's look at the following example: please keep in mind, I tried not to use any higher language features, rather than "language specifics". So this may be ugly nested and not optimal ...
//Check if the string is full of whitepsaces bool allWhiteSpace = true; if(input == null || input.Length == 0) allWhiteSpace = false; else { foreach(char c in input) { if( c != ' ') { allWhiteSpace = false; break; } } }
Lets create a bad helper class called StringHelper, the code gets shorter:
bool isAllWhiteSpace = StringHelper.IsAllWhiteSpace(input);
So, since this is not the only time we need to check this out, I think the “Don't Repeat Yourself” is filled here.
How can we achieve this without an assistant? Given that this piece of code is not associated with one class?
Do we need to inherit a string and call it BetterString?
bool allWhiteSpace = better.IsAllWhiteSpace;
or are we creating a class? StringChecker
StringChecker checker = new StringChecker(); bool allWhiteSpace = checker.IsAllwhiteSpace(input);
So how do we understand that?
Some languages (like C #) allow you to use ExtensionMethods. Do they count helperclasses? I prefer them to belong to helper classes.