Simon Lenz
Simon Lenz

Reputation: 2812

Naming small storage classes in java

i often have in java projects a lot of small helper("storage") classes like 2-Tuple, 3-Tuple, Point, .. (think you know what i mean) Classes that mostly only have class variables, a constructor and getters/setters.

And in my current project, i wanted to store those small classes, that are often used in a lot of other classes in the project in a seperate package. But i do not really know how to name it (my motherlanguage is not english, but code should be for english readers.)

Hope you can give me an answer on this little questions.

Greetings :)

Upvotes: 2

Views: 4585

Answers (5)

Reece
Reece

Reputation: 53

For your information the "storage classes" you are referring to are called Java Beans. Using the popular model view controller design pattern; these would be your model. So lets say you want to put them in a package called model and the domain name of your company is mycompany.com, then the propper java naming convention would be com.mycompany.model; add this line as the first line of code (before any import statements) to all of your Java bean classes:

package com.mycompany.model;

You must also move your Java bean files into a folder structure that is the same. Lets say the file with your main method is in the directory /%ProjectHome%/, then your Java Beans go in a folder /%ProjectHome%/com/mycompany/model/

To compile these files you will now have to change to your /%ProjectHome%/ directory then type javac com/mycompany/model/*.java

Then you will be able to import these files from your other java classes by typing

import com.mycompany.model.*;

Also note, that the Java convention for package names is all lower case, as not to clash with the name space of Class names.

Hope this helps.

Upvotes: 1

Town
Town

Reputation: 14906

I'd go with something like:

utils or the more verbose utilities

you can then break that down further if you need to:

utils.data for data-related utility classes, for example.

Additionally, there's a question here on whether to pluralise or not: Naming convention for utility classes in Java

Upvotes: 2

Devraj
Devraj

Reputation: 71

Different people would name these differently as the names are a matter of personal choice.

A few options:

  1. If the storage classes conform to the Javabeans conventions, you could add the suffix "Bean" eg PointBean

  2. I have also seen a suffix of "DO" or "VO" being used to denote a "data object" or "value object". eg PointDO

  3. You could leave the class name as is eg Point. However if you feel that it does not convey the fact it is a storage class, try to make the package name convey that fact eg com.xyz.valueobjects.Point or com.xyz.dataobjects.Point or com.xyz.storage.Point

Personally I like to use style #3.

Upvotes: 4

Jayy
Jayy

Reputation: 14788

I believe what you're doing is using objects purely for storing data (no behaviour). And since you're talking about tuples, I assume these are used for transferring data to/from your database, so perhaps just "data objects"?

Upvotes: 0

Alanyst
Alanyst

Reputation: 1410

I'd stick those kinds of classes in a *.util package.

Upvotes: 4

Related Questions