views:

105

answers:

4

I reuse a handful of classes for multiple projects, like Postal Address, State, Zip Code and Phone Number. Associated to them maybe parse/format classes (like Phone Number Formatting).

Is it okay to have a JAR with only a couple of classes? An alternative would be to have one "Miscellaneous" JAR with all the classes however it feels dirty to have so few classes for different purposes within the same JAR.

postal.jar
  Address
  Zip
  ZipParser
  ZipFormatter
  State

phonenumber.jar
  PhoneNumber
  PhoneNumberFormatter
  PhoneNumberParser

One jar (with 8 classes) or two (with 5/3 split)?

A: 

Maybe the common purpose could be utilities ? Giving you a single utils.jar

Joel
horrible name. This name would be better suited for a jar that controlled power stations than for a jar that had classes to deal with addresses and phone numbers.
Zak
+2  A: 

It's okay to do it in any way that makes sense for your project(s). However, I guess I would ask the question:

Do you think that you will ever use address without phone number or vice versa on your projects?

To me, those items go pretty hand in hand. Even if you aren't using both right away in some context you could need it soon in the future. I think a jar called something like contact-info.jar makes perfect sense.

Shaun
+1  A: 

If your classfiles will always be deployed together, or if they're closely related ("contact info," in this case), it makes more sense to bundle them in the same jar. Fewer jarfiles may also be easier to deploy, depending on your scenario.

On the other hand, if you have different packages that are completely unrelated (for example, an application-specific package deployed only with certain software releases, and a generic utility package that's deployed with all software releases), then it makes sense to split the classfiles into multiple jars.

I wouldn't consider the classes you've listed to be general-purpose utilities, since storing contact information is more application-specific than, say, working with XML.

rob
A: 

Your classes probably weight only a few (kilo)octets, so you should not bother packaging them in two different jars, one should be fine. And on an additionnal side note, remember that in the long run, when you have to make modifications to these classes, you'll have each time to release this or these jar(s) (building / testing / naming / versionning / publishing them), meaning a few manipulations each time - depending on your build system, it can be more or less fast'n'easy (maybe Maven can help in some cases).

Sergio