Utility classes aren’t exactly evil, but they can violate the principles that compose a good object-oriented design. In a good object-oriented design, most classes should represent a single thing and all of its attributes and operations.
How can we avoid Util class?
- Implementation. Utility Class is usually declared final, so it cannot be subclassed. …
- Testing. Since you have a hard dependency on the Util Class, you cannot easily provide a mock implementation. …
- Inversion of Control. …
- Proxying. …
- Single Responsibility.
Should utility classes be static?
Declaring it to be static will save memory too. A screw driver doesn’t change, it always do the same thing. If the same can be said for your utility class, definitely make it static. This hold true for all methods that do not rely on the state of the object.