UML: Modeling Software Architecture with Packages
6-8 minutes
If a system is big, it should be partitioned in smaller sub-systems, each with its own class diagram. In UML notation, the partitions/sub-systems are called packages. A package is a grouping of model elements, and as such, it is a UML construct used also in other UML diagrams. Packages themselves may be nested within other packages that basically the UML version of a directory, a place to put things. Package diagrams are typically applied for the following cases:
- Provide a way to group related UML elements and to scope their names
- Provide a way to visualize dependencies between parts of your system
- Vulnerable to changes (in other packages)
- Provide support for analysis
- Determine compilation order
Package Diagram at a Glance
Package diagram is used to simplify complex class diagrams, you can group classes into packages. A package is a collection of logically related UML elements.
The diagram below is a business model in which the classes are grouped into packages:
- Packages appear as rectangles with small tabs at the top.
- The package name is on the tab or inside the rectangle.
- The dotted arrows are dependencies.
- One package depends on another if changes in the other could possibly force changes in the first.
Package Diagram Namespace
Packages contain different elements (packages too). A UML package establishes a namespace for specifying the context of a UML. A package defines what is known as an encapsulated namespace. When an element in one space needs to refer to an element in a different namespace, it has to specify both the name of the element it wants and the qualified name or pathname of the element (compare to file system analogy). You provide the fully scoped name, for example,
package Name::class Name
In Java, a fully-scoped name corresponds to specify the Java package. It is possible to specify visibility for owned and imported elements, such as, public or private as well.