Sunday, November 23, 2003

J2EE: Of packages and script libraries

Packages are away of organising you code in java, just the same as script libraries in Domino. The rather dinky Elements of java style states:

"Place types that are commonly used changed, and released together; or mutually dependent on each other; into the same package."

Examples being:

Calendars Dates and Times
Points and polygons etc etc

They go on to give even more advice on using packages to isolate volatile classes; making sure you are careful about dependencies between packages; and using packages as the effective unit of release (rather than individual classes).

Its all rip roaring stuff (really?). Thing is how do they look in real life? It's all very well to bang on about polygons and circles, but I can't remember the last bit of code I wrote that needed any. That's a lie actually, I did write a program in basic in 1983 called the "Purple poo eater" that needed a circle, but that's another story.

Anyhow, whats a real world example of packages? In the extraordinarily absorbing Enterprise Programming with websphere they give a good example of packaging in J2EE application.

The packages are based on the architectural layer so the names could be:

  • domain: business logic stuff

  • mediator:mediator classes

  • panel: panels in presentation layer classes.

  • system: system classes used to provide services to all layers

  • testscripts: testscripts used to drive the domain logic

  • mapping: mapping layer classes, that is mapping between objects and a relational back end database

  • controller: controller layer

  • applet: applets stupid

  • frame: frames defined for standalone applications

  • util: utility classes independent of any layer

Following this convention, the packages for a simple J2EE app could be:
  • com.spuggy.domain

  • com.spuggy.servlet

  • com.spuggy.mediator

  • com.spuggy.system

  • com.spuggy.util

  • com.spuggy.testscript

Finally it's worth mentioning that Elements of java style is co-authored by the fantastically named Greg Bumgardner. I tried to search google to find a link to him, and by accident stumbled on the legendary Rusty Bumgardner. Go Rusty.

This page is powered by Blogger. Isn't yours?