Namespaces and Packages
Go Up to Modeling Concepts
In the Modeling feature's documentation, the terms package and namespace are almost synonymous. The term package is used for design projects, while the term namespace is used for implementation projects.
In the UML, packages provide a general purpose mechanism for organizing any modeling elements together into groups. A package is a UML model element that contains a set of named elements that can be identified by their names. The most common use of packages is to group classes.
In the Modeling feature, a modeling project consists of one or more packages (or namespaces). Each class should be a member of a single package. Packages can also be members of other packages. A package can contain both subpackages and classes (and other packageable elements like interfaces, enumerations, and others).
Each modeling project contains the default package (or namespace) created automatically.
In diagrams, packages are shown as tabbed folders:
Contents of a package (namespace) can be displayed in a special type of Class diagrams -- Package diagrams (or Namespace diagrams).
In programming terms, packages correspond to such grouping constructs as namespaces (in C++ and Delphi). Each package represents a namespace, which means that every class must have a unique name within its owning package. For example, if you want to create a class called Account
, and an Account
class is already in a
Banking
package, you can have your own Account
class as long as you put it in a separate package. To make it clear which of the Account
classes to use, you can use a fully qualified name, that is, a name that shows the owning package. For example, you can use the Banking::Account
and MyUtils::Account
fully qualified names.
You can use packages to control the visibility of elements so that some elements are visible outside the package, while others are hidden.
You can use packages to present different views on your system.