How to refactor methods form a utils class to most relevant places?
posted 3 years ago
I am looking for a tool or a way to refactor w large utils class with lots of private and public static methods and put those methods to the classes that are accessing them. In total there 12 classes in two packages that use the methods in the utils class. If you know any tool or any best practice to refactor check where each method or set of methods should be placed please let me know.
Some of the classes in those packages have common ancestors which can be good place for the common methods but some classes are isolated.
Are you having an open source project ?
If it is possible to contact the project's owner, you can have this discussion there.
However, Utility classes generally do opposite of what you seem to be proposing- they externalize the code from their users to a central class to promote re-usability.
As they grow in size, one possible refactoring I can come up with is creation of multiple utilities, extending a common utility class.
While your assumption about common ancestors is valid, but many methods might also be required by non-common ancestors to execute in isolation and/or cause their classes to lose cohesiveness.
Tool: In eclipse, Alt+Shift+T brings up the refactor menu (you can use commands to refactor the code directly)
Resource: Martin Fowler's refactoring book+website