Q: Designing Helper/Utility classes - java Maybe this question is general but I did not find an answer I was looking for, so I was hoping to get some ideas from this post. I am trying to move out some commonly used methods to a helper to simplify my design. I looked at multiple posts and debate about making the utility methods static v/s non-static. My question is more related to creating a helper classes with a combination of static and non-static methods. Since the existing class contains a combination of static and non-static methods that I want to move out as I do not want duplicate code in multiple classes. So, I was wondering if it is a good idea to include both static and non static methods in the helper class. The reason I am a little hesitant is most utility methods are static in nature and I want to understand if it a good design choice to have static and non-static methods in utility classes. Any suggestions??

A: It depends on what the class is doing.
Non-static methods imply that the helper class maintains some state that can be different across different instances.  If you don't have that then all static methods is the way to go (think like the java Math or Collections classes).
If you need to maintain instance state across method calls, then non-static methods are useful.  If you go in this direction, then your helper class will have constructors or static factory methods that create Helper objects and each instance will have fields that maintain state.
non-static methods might also be a good idea if your otherwise static methods often have the same parameters over and over again that are all the same values/references.  In that case it might be cleaner to make those constructor parameters and just have the method parameters for the additional parameters that differ between the methods.
