Is it good to have "Utils" class in your software project? [closed]

Solution 1:

Its absolutely a best practice! you don't want to mix all those utility functions with the rest of your application business logic. However, as your utils files and/or classes grow it is recommended to group them according to the function they provide.

For example, in a web application you could end up with a package structure like this.

org.sample.web.model
org.sample.web.utils
org.sample.web.validators
org.sample.web.validators.utils

Solution 2:

Yes, utility classes are a good idea but, as with all object-oriented programming, you should be aiming for maximum cohesion, minimal coupling.

Maximum cohesion means that everything in a single class should be heavily related to each other. Minimal coupling means there should be no unnecessary dependencies between classes.

In other words, lumping together compression with image manipulation or the launching of external processes in a single class is a bad idea. By all means have a compression utility class and an image manipulation utility class but don't put them together.

Doing so is akin to using the singleton pattern as a god object, a ghetto where you just dump all your rubbish that should be better organised. I would say it's okay to use an uber-utility class during development but make sure your code is better organised before shipping. Maintenance will be a lot easier.

Is it a good practice?

No, not in the long term although it's useful when done temporarily.

Will things grow unmanageable when the number of functions grow larger and larger?

Yes, no question about it.