Custom Java Utility Package

A common operation in my current project is converting a string version of an IP address to an integer representation and is easily handled by one static method. I usually try to keep this as close as possible to the code that uses it as much as possible, but it is also needed in completely different parts of the application.

Since the classes in very different packages seemed to relate to each other for this one utility, I created the package utiland moved the static methods (one for int to String, one for String to int) to the class Ipin that package.

I understand that this is probably a sign that I should rethink the organization of the project, but is there anything harmful to add a package to store the general functions of the project? Is there a standard way to handle this situation in Java?

+5
source share
7 answers

This is a common problem, not just Java.

"Since it seemed harmful" - what harm? Connection? The only point of failure?

You have an example of what you did in the JDK itself: it java.utilhas many classes that are used everywhere.

I think your design is justified. Keep it this way until experience tells you the best place to place this class.

, , . , - . , .

+6

. , , , , , . , , .

, , , - .

+3

, . util , , , .

, , . , , util.

.

+2

- ?

. util - , .

, . ,

+2

, , , , , - , - .

+1

" " . Code Complete (2- .), " ":

, . , .

+1

- , , , . . java.util.Collections, (, ) , Collection. .

0

All Articles