Question

About code organisation in packages, i have seen both tools and util used for the same purpose, ie. to contain classes that help with trivial and frequent tasks.

Example:

+ foo.util
|--  StringManipulation.java
|--  MyLogger.java
+ foo.tools
|--  InputSanitization.java
|--  IdentifyOS.java
|--  Whatever.java

From your experience, is there anything that distinguishes tools from utils?
How should such reusable code be organised?

Was it helpful?

Solution

Both "tools" and "utils" are bad names for classes/packages. It is not object oriented. It is a way of saying, "I don't know what to name this thing so I'll just give it a generic name".

What you should do is figure out what these tools/utils are really doing and name them appropriately.

OTHER TIPS

Classes within the same package usually share the same or similar functionalities, or they together achieve a set of similar functionalities. In addition, classes within the same package can access all package-private variables (i.e., those variables defined without public, protected, and private) within their package.

As for naming, while Oracle has defined a convention for java naming packages, it is developer's responsibility to have a clear naming for each package. In your case, it is better to have some descriptions to describe the utilities and tools. Here are some examples:

foo.connection.tools
foo.string.utils

In this way, users can know the tools is for connections, utils is for string manipulations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top