6 - Packaging Conventions
Published online by Cambridge University Press: 07 September 2010
Summary
This section contains guidelines for creating packages. See Rules #15–17 for conventions related to package naming.
Place types that are commonly used, changed, and released together, or mutually dependent on each other, into the same package.
This rule encompasses several related package design principles:
The Common Reuse Principle
A package consists of classes you reuse together.
If you use one of the classes in the package, you use all of them.
Place classes and interfaces you usually use together into the same package. Such classes are so closely coupled you cannot use one class without usually using the other. Some examples of closely related types include
■ Containers and iterators.
■ Database tables, rows, and columns.
■ Calendars, dates, and times.
■ Points, lines, and polygons.
The Common Closure Principle
A package consists of classes, all closed against the same kind of changes. A change that affects the package affects all the classes in that package.
Combine classes that are likely to change at the same time, for the same reasons, into a single package. If two classes are so closely related that changing one of them usually involves changing the other, then place them in the same package.
The Reuse/Release Equivalence Principle
The unit of reuse is the unit of release. Effective reuse requires tracking of releases from a change control system. The package is the effective unit of reuse and release.
- Type
- Chapter
- Information
- The Elements of Java™ Style , pp. 89 - 94Publisher: Cambridge University PressPrint publication year: 2000