JAR Design Over Class Design
In early December, I spoke at SpringOne Americas and delivered a session on OSGi. Whenever I speak about application design or architecture, I always ask the audience three questions at the beginning of the session. In this session, I had about 40 or 50 folks in attendance, and here’s a rough breakdown of the hands shown after each of the questions.
- How many spend time designing classes, both the behavior of a class and the relationships between classes? Almost everyone raised their hands.
- How many spend time designing packages, both the behavior of a package and the relationship between packages? Only about 5 hands went up.
- How many spend time designing JAR files, both the behavior of a JAR and the relationship between JAR files? Only about 2 or 3 hands went up.
These are common responses. Most development teams spend time designing classes, but few spend time designing JAR files. That’s unfortunate, because failing to design JAR files inhibits reusability and hinders maintenance. Even the most flexible class design is severely compromised if all classes are packaged and bundled into the same module.
When designing software systems, more effort should be devoted to designing the granularity of JAR files and managing the relationships between JAR files. When designing classes, more effort should be devoted to designing classes whose relationships
span JAR files, with less effort devoted to classes whose relationships
are encapsulated within a JAR file. Why? Classes whose relationships are encapsulated within a JAR file are isolated from the rest of the application, and can be more easily refactored because the ripple effect of change is constrained to the JAR file. Packages, as the intermediary logical concept, are important in helping bring greater internal design resiliency to a JAR file.
And, of course, design is a evolutionary activity involving many tasks, including a combination of modeling, coding, and testing.
From http://techdistrict.kirkk.com/
- Login or register to post comments
- 3393 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
tmilard replied on Thu, 2009/01/08 - 4:28am
I think perhaps will easier tools to manage/update jars inside tools could help us.
Gilbert Herschberger replied on Thu, 2009/01/08 - 2:47pm
For those of us who have been spending a lot of time working on the design of jars and relationships between jars, what do you think are the basic rules of good jar design? We might start with the following list.
Jar design is an excellent topic for discussion. We need hints, suggestions and recommendations.
Thanks,
Phil Zoio replied on Fri, 2009/01/09 - 4:46am
It does not surprise me that more people didn't admit to designing jar or package relationships - but that's exactly what lead to spagetti code and systems. OSGi and modularity frameworks such as Impala strongly encourage you to think about these things, which is essential if you want to write modular applications.
A couple of other rules of thumb I'd like to add to Gilbert's:
11. Make sure you eliminate package cycles from your jars.
12. Give each jar it's own base package. For example, foo.jar contains com.myapp.foo and subpackages. This makes sure that you don't end up with packages split across jars (a no-no in OSGi), and also self-documents the location of packages.
Phil Zoio
http://impala.googlecode.com - Impala dynamic modules