Package diagrams

In UML, packages logically group elements together and provide a namespace for the groups. Many UML elements, such as classes, use cases, and components, can be grouped together in packages. Packages can also contain other packages. Package diagrams are used to show the dependencies between packages in a software system.

The more complex a software system is, the more difficult it can be to understand all of the models. Package diagrams make it easier for people to reason about large, complex systems by grouping elements together and allowing us to see the dependencies.

In addition to modeling standard dependencies, we can model package import and package merge types of dependencies. A package import is a relationship between an importing namespace and an imported package. This can allow us to reference package members from other namespaces without fully qualifying them. A package merge is a relationship between two packages in which one package is extended by the contents of another package. The two packages are essentially combined.

A package is graphically represented in UML by a symbol that looks like a file folder with a name. The following is an example of a high-level package diagram for a layered application:

By looking at it, we can see that the Presentation Layer depends on theĀ Business Layer, the Business Layer depends on theĀ Data Layer, and all three layers depend on the Cross-Cutting package.