Previous | Table of Contents | Next |
A package is used to group elements, and provides a namespace for the grouped elements.
A package is a namespace for its members, and may contain other packages. Only packageable elements can be owned members of
a package. By virtue of being a namespace, a package can import either individual members of other packages, or all the members
of other packages.
In addition a package can be merged with other packages.
• “PackageableElement? on page 145
• “Namespace? on page 143
No additional attributes
• /nestedPackage: Package [*] References the owned members that are Packages. Subsets Package::ownedMember and redefines Basic::Package::nestedPackage.
• ownedMember: PackageableElement [*] Specifies the members that are owned by this Package. Redefines Namespace::ownedMember.
• ownedType: Type [*] References the owned members that are Types. Subsets Package::ownedMember and redefines Basic::Package::ownedType.
• package: Package [0..1] References the owning package of a package. Subsets NamedElement::namespace and redefines Basic::Package::nestingPackage.
• packageMerge: Package [*] References the PackageMerges that are owned by this Package. Subsets Element::ownedElement.
Constraints
[1] If an element that is owned by a package has visibility, it is public or private.
self.ownedElements->forAll(e | e.visibility->notEmpty() implies e.visibility = #public or e.visibility = #private)
[1] The query mustBeOwned() indicates whether elements of this type must have an owner.
Package::mustBeOwned() : BooleanmustBeOwned = false
[2] The query visibleMembers() defines which members of a Package can be accessed outside it.
Package::visibleMembers() : Set(PackageableElement);visibleMembers = member->select( m | self.makesVisible(m))
[3] The query makesVisible() defines whether a Package makes an element visible outside itself. Elements with no visibility
and elements with public visibility are made visible.
Package::makesVisible(el: Namespaces::NamedElement) : Boolean;pre: self.member->includes(el)makesVisible =
-- the element is in the package(ownedMember->includes(el)) or-- it is imported individually with public visibility(elementImport->
select(ei|ei.visibility = #public)->
collect(ei|ei.importedElement)->includes(el)) or-- it is imported through a package with public visibility(packageImport->
select(pi|pi.visibility = #public)->collect(pi|pi.importedPackage.member->includes(el))->notEmpty())
A package is a namespace and is also a packageable element that can be contained in other packages.
The elements that can be referred to using non-qualified names within a package are owned elements, imported elements, and
elements in enclosing (outer) namespaces. Owned and imported elements may each have a visibility that determines whether they
are available outside the package.
A package owns its owned members, with the implication that if a package is removed from a model, so are the elements owned
by the package.
The public contents of a package are always accessible outside the package through the use of qualified names.
A package is shown as a large rectangle with a small rectangle (a “tab?) attached to the left side of the top of the large
rectangle. The members of the package may be shown within the large rectangle. Members may also be shown by branching lines
to member elements, drawn outside the package. A plus sign (+) within a circle is drawn at the end attached to the namespace
(package).
• If the members of the package are not shown within the large rectangle, then the name of the package should be placed within the large rectangle.
• If the members of the package are shown within the large rectangle, then the name of the package should be placed within the tab.
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). Package elements with defined visibility may not have protected or package visibility.
A tool may show visibility by a graphic marker, such as color or font. A tool may also show visibility by selectively displaying
those elements that meet a given visibility level (e.g., only public elements). A diagram showing a package with contents
must not necessarily show all its contents; it may show a subset of the contained elements according to some criterion.
Elements that become available for use in an importing package through a package import or an element import may have a distinct
color or be dimmed to indicate that they cannot be modified.
There are three representations of the same package Types in Figure 11.27. The one on the left just shows the package
without revealing any of its members. The middle one shows some of the members within the borders of the package, and the
one to the right shows some of the members using the alternative membership notation.
Types | |||||
Integer | |||||
Time |
Types
Shape Point
Figure 11.27 - Examples of a package with members