This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes package structure during design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "package structure during design" Watch "package structure during design" New topic
Author

package structure during design

nibla jose
Greenhorn

Joined: May 25, 2009
Posts: 28
I have 4 layers in my application. Also my requirement needs me to implement around 9 modules in the application. How should my package structure be?

1. com.clientcompany.business.module1.class
com.clientcompany.business.module2.class

com.clientcompany.web.module1.class
com.clientcompany.web.module2.class

OR

2. com.clientcompany.module1.business.class
com.clientcompany.module1.web.class

com.clientcompany.module2.business.class
com.clientcompany.module2.web.class

1. Which one is more desirable and Why?
2. Is there any general rules to package the classes like this?
3. Are there any standards for this?

All kind replies thankfully appreciated.


Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
I recommend a third option.
com.clientcompany.module1
com.clientcompany.module2
com.clientcompany.ui.web
com.clientcompany.ui.web


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
I would always try to put the domain as top level and the other layers below it. it focuses more on the domain and you don't get "distracted" by the sublayers when browsing on the most top level package.

e.g.:
com.user.services
com.user.model
com.payments.model
com.payments.services

aldana software engineering blog & .more
nibla jose
Greenhorn

Joined: May 25, 2009
Posts: 28
@manuel aldana..
Thanks for the reply..
But does it depend anyway on the archiving (JARing), like if
1. we are archiving each domains/modules into separate EARs OR
2. we are archiving each layers into an EAR or WAR (like subsystems) ???

Do we need to take account of the mode of archiving for delivery? I know we can archive parts of a java package in single JAR and the other parts in another? But is this a good practice?

Presently, in my case, I will be archiving all my business classes as EJB Jar. All the modules that i develop is to be run in a sinle EAR. So I have given the package structure as 'com.cleintcompany.business.module1' so that when i pack the source files as the EJB Jar all files under 'com.cleintcompany.business' will be in a single JAR. Does this sound okay? Is this the right approach to do package design?

manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
itself the packaging approach and distribution are two things.

if the size of the subsystem/module is tiny it is not worth to put them into own .jars (by having jars you add additional complexity in packaging and distribution).

but if they are big do a split. so when i got two big subsystems:
com.company.user
com.company.payments
they would result into jars. user-1.2.jar + payments-1.2.jar (if they are EJB related these jars would be EJB-modules). they would then be packed to the .ear archive.

btw I often use maven, it introduces a nice multimodule project concept which gives you a lot of help with packaging and dependency-management.



nibla jose
Greenhorn

Joined: May 25, 2009
Posts: 28
Thanks manuel aldana,
The reply was helpful..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package structure during design
 
Similar Threads
Unable to run servlet on my machine
How to jar a package
Struts2: Problem with form validation using validation xml
jsp servlet sql server
B&S: Design observation: value object Design pattern.