• Post Reply Bookmark Topic Watch Topic
  • New Topic

Packaging best practices  RSS feed

 
Jeff Zohrab
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I've searched for any text on Java packaging best practices, particularly with regard to program structure and minimizing dependencies, but can't find anything. I hope I can get some help.

I have a (fairly procedural) portion of a program to do some processing. The processing procedure is in its own package, as it has helper classes, etc, and I felt that this was a good way to express the intent of the program to maintenance/production support. This package also contains some subpackages, which handle moderately complicated subprocessing on their own. These subpackages have some common requirements (such as data source interfaces, and result collectors), so it made sense to pull these out of the subpackages ... but I wasn't sure where to put them: in the main package, or in yet another subpackage in the main package?

Example:



Question: Where should Helper go? In package process? Or in a third helper package, process.helpers? The former seems OK as it keeps the number of packages down, but it seems funny that there are package dependencies both ways (from the parent to the child, and from the child back to the parent). The latter seems potentially clearer, as there wouldn't be any circular package dependencies (even for nested packages), but there may be some drawbacks to this I'm not aware of, such as the explosion of packages.

Really the question boils down to dependencies and how to keep things obvious and clean. I can import everything, but it seems sloppy. Advice or references would be appreciated.

Thanks,

Jeff
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a natural tendency to try to minimize the number of classes and packages in a project because of an intuitive feeling that proliferation of lots of classes and packages is going to be "inefficient" or "complex" or both. Fight the tendency, because while your heart is in the right place, the results are the opposite of what you want. More, smaller packages leads to easier understanding. Just looking at a list of 20 classes in one package vs. looking at a list of 5 subpackages, then just the four classes you want, is obviously more complex, not less.

So I vote for the "helpers" subpackage.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you mentioned an interest in package dependencies, I'll point you to Uncle Bob (Robert Martin) via this blog entry and his PPP Book. The book is my top recommendation for anybody interested in improving their OO practices.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!