UML Package Diagrams Notation
Package diagram is UML structure diagram which shows packages and dependencies between the packages.
Model diagrams allow to show different views of a system, for example, as multi-layered (aka multi-tiered) application - multi-layered application model.
The following nodes and edges are typically drawn in a package diagram: package, packageable element, dependency, element import, package import, package merge.
Package
Package is a namespace used to group together elements that are semantically related and might change together. It is a general purpose mechanism to organize elements into groups to provide better structure for system model.
Owned members of a package should all be packageable elements. If a package is removed from a model, so are all the elements owned by the package. Package by itself is packageable element, so any package could be also a member of other packages.
Because package is a namespace, elements of related or the same type should have unique names within the enclosing package. Different types of elements are allowed to have the same name.
As a namespace, a package can import either individual members of other packages or all the members of other packages. Package can also be merged with other packages.
A package is rendered as a tabbed folder - a rectangle with a small tab attached to the left side of the top of the rectangle. If the members of the package are not shown inside the package rectangle, then the name of the package should be placed inside.
Package org.hibernate
The members of the package may be shown within the boundaries of the package. In this case the name of the package should be placed on the tab.
Package org.hibernate contains SessionFactory and Session
A diagram showing a package with content is allowed to show only a subset of the contained elements according to some criterion.
Members of the package may be shown outside of the package by branching lines from the package to the members. A plus sign (+) within a circle is drawn at the end attached to the namespace (package). This notation for packages is semantically equivalent to composition (which is shown using solid diamond.)
Package org.hibernate contains interfaces SessionFactory and Session.
The elements that can be referred to within a package using non-qualified names are:
- owned elements,
- imported elements, and
- elements in enclosing (outer) namespaces.
Owned and imported elements may have a visibility that determines whether they are available outside the package.
If an element that is owned by a package has visibility, it could be only public or private visibility. Protected or package visibility is not allowed. The visibility of a package element may be indicated by preceding the name of the element by a visibility symbol (“+” for public and “-“ for private).
All elements of Library Domain package are public except for Account
The public elements of a package are always accessible outside the package through the use of qualified names.
Package URI Attribute
Package has optional URI attribute which serves as unique identifier of the package. This attribute was introduced in UML 2.4 mostly to support exchange of profiles using XMI.
Note, that UML 2.4 specification requires this URI attribute to follow the rules and syntax of the IETF URI specification RFC 2396 while the more recent version of the URI syntax RFC 3986 (released in 2005) rendered the RFC 2396 obsolete.
Both RFCs allow URIs to be uniform resource locators (URLs), uniform resource names (URNs) or both. Though URN actually defines item’s identity (unique id) and URL provides a method for finding it, it is very common and sometimes confusing to see URLs serving as URNs.
Here’s some examples of package URI attribute in the form of URL. Note, that using “http://“ scheme is often not related to HTTP protocol and no actual resource is located at that location. URL is just used as a substitute of unique id:
- http://www.ietf.org/rfc/rfc2396.txt
- http://www.omg.org/spec/UML/20100901/PrimitiveTypes.xmi
- http://www.uml-diagrams.org/profiles/20110410/EJB-30.xmi
My personal preference is to use URNs instead, as URN was designed specifically to define identity (unique id) and does not imply availability of the identified resource (e.g. for obsolete resources):
- urn:ietf:rfc:3986
- urn:oasis:names:specification:docbook:dtd:xml:4.1.2
- urn:schemas-microsoft-com:xml-data
- urn:uml-diagrams-org:profiles:20110410:EJB-30
The URI attribute of a package may be rendered in the form {uri=
EJB Profile shown as a package with URI attribute.
Package Template
Package can be used as a template for other packages. Note, that [UML 2.4.1 Specification] inconsistently calls it both package template and template package.
Packageable element can be used as a template parameter. A package template parameter may refer to any element owned or used by the package template, or templates nested within it.
A package may be bound to one or more template packages. When several bindings are applied the result of bindings is produced by taking the intermediate results and merging them into the combined result using package merge.
Package template Service Provider and bound package Scheduler Service.
Packageable Element
Packageable element is a named element that may be owned directly by a package.
Some examples of packageable elements are:
- Type
- Classifier (—> Type)
- Class (—> Classifier)
- Use Case (—> Classifier)
- Component (—> Classifier)
- Package
- Constraint
- Dependency
- Event
Packageable element by itself has no notation, see specific subclasses.
https://www.uml-diagrams.org/package-diagrams.html#packageable-element