Why is it considered such an anti-pattern in all cases to use static methods rather than singletons?
I originally wrote the following code
class MyValidator {
public static boolean isValid(String mystring){
if (some conditions ...) {
return true
} else {
return false
}
}
}
I can't really see a reason to make this into an object. It seems just fine as a static method - more testable, eliminating state, etc.
However, I ran into an issue upstream when I wanted to write a controller unit test and mock out the isValid() call. I realize I can use libraries like PowerMock, but people seem to religiously think doing this is an antipattern.
Why is that and what's so wrong with keeping this static?