One of the first things to do when starting a new project is to choose a hierarchy of package names to represent the work that is being done.  This is not as easy as it sounds.  

The hierarchy of the packages can be the only thing that uniquely differentiates your software from any other.  The package structure is usually the reverse of the URL the software would have if it was made available on the internet - even if it is not a web application.  This is best illustrated by examples.

Example

Package name to be used?

A global company, Hyro is writing some internal timesheet software for use by its own staff.

com.hyro.timesheet.* in the Hyro source code repository

A global company, Hyro is writing an application on behalf of a local Australian company, Bright Brewery.

au.com.brightbrewery.* in the Hyro source code repository.  This package structure would be used even if the resulting product was not for use on the Internet.

So, the prefix for the package names are standardized:

Package

Contents

java.*

All default java code libraries published by Sun Microsystems.  Unlike the early days of C and C++, this codebase usually consists of rock-solid code and clearly designed APIs.  Off limits.

org.*

Community code, generally provided free for all to use as open source.

net.*

Similar to org.* this code is usually for community open source projects.

com.*

Commercial/company code, usually owned by a company.

com.thecompany.*

All software written for a particular company.  “thecompany” is usually the one paying for the software to be written.

com.thecompany.theproject.*

All software for the project exists beneath here.  For example, common utilities for the entire project would be placed in com.thecompany.theproject.util

au.com.thecompany.*

Strictly Australian-only companies would have au.com at the beginning.

au.net.*

For community Australian-only organisations.  Etc.

Avoid naming packages with a plural meaning; don't put an 's' on the end.  For example – if you have a package for “models”, rename it to “model”, much like the java.util package.  The existence of the package implies plurality so the 's' is pointless.

Trap! Package names never have upper case letters in them, even where two words are joined together.  Numbers should generally not be used as part of package names.

blog comments powered by Disqus