Package Diagram Tutorial

Package diagram shows the arrangement and organization of model elements in middle to large scale project that can be used to show both structure and dependencies between sub-systems or modules.

Package Diagram Example

What is a Package Diagram in UML?

Big systems offer special challenges. Draw a class model for a large system, and it is too big to comprehend. There are too many links between classes to understand. A useful technique to handle this is that of UML's packages. A package in the Unified Modeling Language helps:

  1. To group elements
  2. To provide a namespace for the grouped elements
  3. A package may contain other packages, thus providing for a hierarchical organization of packages.
  4. UML elements can be grouped into packages.

The illustration below shows an example package diagram is used to represent the composition of a business.

Package Diagram: Business composition

Try it!

Finding an online Package Diagram tool? Just click the draw button on the right to create your Package Diagram online. Visual Paradigm Online is free* and intuitive. You can also go through this Package Diagram tutorial to learn about Package Diagram before you get started.

Draw Now

Package Diagram Notations

Package diagrams are used to structure high level systems. Packages are used for organizing large system which contains diagrams, documents and other key deliverables. In other words, packages can be used as a part of other diagrams also.

Nested and Hierarchical Packages

A package can be represented as a hierarchical structure with nested packages. Atomic module for nested package are usually class diagrams.

The figure below gives an example of package diagram that consists of several nested packages.

Package Diagram: Java date package

There are few constraints while using package diagrams, they are as follows.

  1. The name of packages should be unique within a system. However, it is allowed for classes inside different packages to have same name. For Example, Package::Product & Shipping::Product are allowed.
  2. Users should avoid using package name delivered by the programming language. For Example, Java provides Date as a package. So, programmers should construct package with name Date.
  3. Packages can include whole diagrams, name of components alone or no components at all.

A package can also has a fully qualified name. The figure below shows an example use of such a package.

Fully qualified package

Note That:

  1. UML, C++, Perl, Ruby myPkg::foo::bar
  2. Java, C# myPkg.foo.bar

Package Containment

  1. Packages are shown in static diagrams
  2. Two equivalent ways to show containment:
    Package Diagram

Dependency

There are two sub-types involved in dependency. They are <<access>> & <<import>>. Though there are two stereotypes users can use their own stereotype to represent the type of dependency between two packages.

<<import>> - one package imports the functionality of other package

Package import example

Example – <<import>> Dependency

Package Diagram import example

<<access>> - one package requires help from functions of other package

Package Diagram: Access

When to draw Package Diagram?

The UML does not treat package diagrams as a separate technique, It is often useful to combine them by grouping other model elements together into different packages on the same diagram. Package diagrams can be useful in many ways, such as:

  1. To create an overview of a large set of model elements
  2. To organize a large model
  3. To group related elements
  4. To separate namespaces

Criteria for Decomposing a System into Packages

  1. Different owners - who is responsible for working on which diagrams?
  2. Different applications - each problem has its own obvious partitions;
  3. Clusters of classes with strong cohesion - e.g., course, course description, instructor, student,...
  4. Or: use an architectural pattern to help find a suitable decomposition such as MVC Framework

Other Guidelines for Packages

  1. Gather model elements with strong cohesion in one package
  2. Keep model elements with low coupling in different packages
  3. Minimize relationships, especially associations, between model elements in different packages
  4. Namespace implication: an element imported into a package does not "know" how it is used in the imported package

How to Create a Package Diagram?

The following example shows the Track Order Service for an online shopping store.

Track Order Service is responsible for providing tracking information for the products ordered by customers. Customer types in the tracking serial number, Track Order Service refers the system and updates the current shipping status to the customer.

Step 1 - Identify the packages present in the system

  1. There is a "track order" service, it has to talk with other module to know about the order details, let us call it "Order Processing".
  2. Next after fetching Order Details it has to know about shipping details, let us call that as "Shipping".
  3. Finally if knows the status of the order it has to update the information to the user, let us call this module as "UI Framework".
Package Diagram: Identify packages

Step 2 - Identify the dependencies

  1. "Track order" package should get order details from "Order Processing" and on the other hand, "Order Processing" also requires the tracking information from the "Track Order" package, thus, the two modules are accessing each other which suffices <<access>> dual dependency.
    Package Diagram: Identify dependencies
  2. To know shipping information, "Shipping" requires to import "Track Order" to complete the shipping process.
    Package Diagram: Identify import

Step 3 - Finally, Track Order dependency to UI Framework is also mapped in to the diagram which completes the Package Diagram for Track Order subsystem.
Package Diagram example


Package Diagram Examples

Package Diagram Example – MVC Structure

Package Diagram Example: MVC Structure

Package Diagram Example - Layering Structure

Package Diagram Example: Layered Structure

Want to draw a Package Diagram?

You've learned what a Package Diagram is and how to draw a Package Diagram step-by-step. It's time to get your hands dirty by drawing a Package Diagram of your own. Draw UML diagrams free* with Visual Paradigm Online. It's easy-to-use, intuitive.

Draw Now

* The Express edition supports free usage of Visual Paradigm Online for non-commercial use only.