Private static methods might be a smell

I was extracting smaller methods out of existing big ones, in a class I was working on. Some of these extracted methods became “utility methods”: they would perform some operation on the parameters given to it, but not use any of the fields in the class. These methods could just as well have been static.

I ended up with a set of these methods, most of them accepting the same parameter. In this case, the common object was a Set. Seeing the pattern emerge, I created a new object called ProductSet and moved all the private static methods there. In this class, they would instead become public non-static methods. The code immediately felt better. As I continued working, I found even more code that really belonged on this ProductSet object and it became one of the main abstractions in the code.

So, to summarize, my insight of the day:

A sign that the Move Method refactoring might be appropriate is that you have private static methods in a class (or private methods that could as well be static). If it doesn’t use any of the class’ fields, then maybe it belongs elsewhere.