Previous UML Classes Table of Contents UML Packages Next

7.3.34 Namespace


   A namespace is an element in a model that contains a set of named elements that can be identified by name.



    NamedElement (from Kernel , Dependencies ) on page 99.


   A namespace is a named element that can own other named elements. Each named element may be owned by at most one namespace. A namespace provides a means for identifying named elements by name. Named elements can be identified by name in a namespace either by being directly owned by the namespace or by being introduced into the namespace by other means (e.g., importing or inheriting). Namespace is an abstract metaclass.

   Issue 8083 - Reword to eliminate confusion about constraint associated with namespace.

   A namespace can own constraints. A constraint associated with a namespace may either apply to the namespace itself, or it may apply to elements in the namespace.

   A namespace has the ability to import either individual members or all members of a package, thereby making it possible to refer to those named elements without qualification in the importing namespace. In the case of conflicts, it is necessary to use qualified names or aliases to disambiguate the referenced elements.


   No additional attributes


   • elementImport: ElementImport [*] References the ElementImport s owned by the Namespace . Subsets


   • ownedRule: Constraint[*] Specifies a set of Constraints owned by this Namespace . Subsets

   Namespace ::ownedMember

   • packageImport: PackageImport [*] References the PackageImport s owned by the Namespace . Subsets



   [1] All the members of a Namespace are distinguishable within it.


   [2] The importedMember property is derived from the ElementImport s and the PackageImport s.

   elf.elementImport.importedElement.asSet()->union(self.packageImport.importedPackage->collect(p |p.visibleMembers()))))

   Additional Operations

   [1] The query getNamesOfMember() gives a set of all of the names that a member would have in a Namespace . In general a member can have multiple names in a Namespace if it is imported more than once with different aliases. The query takes account of importing. It gives back the set of names that an element would have in an importing namespace, either because it is owned; or if not owned, then imported individually; or if not individually, then from a package.

   Namespace ::getNamesOfMember(element: NamedElement ): Set(String);getNamesOfMember =if self.ownedMember ->includes(element)then Set{}->include( let elementImports: ElementImport = self.elementImport->select(ei | ei.importedElement = element) inif elementImports->notEmpty()then elementImports->collect(el | el.getName())else

   self.packageImport->select(pi | pi.importedPackage.visibleMembers()->includes(element))-> collect(pi | pi.importedPackage.getNamesOfMember(element))



   [2] The Boolean query membersAreDistinguishable() determines whether all of the namespace’s members are distinguishable within it.

   Namespace ::membersAreDistinguishable() : Boolean;

   membersAreDistinguishable =

   self.member->forAll( memb |

   self.member->excluding(memb)->forAll(other |

   memb.isDistinguishableFrom(other, self)))

   [3] The query importMembers() defines which of a set of PackageableElement s are actually imported into the namespace. This excludes hidden ones, i.e., those that have names that conflict with names of owned members, and also excludes elements that would have the same name when imported.

   Namespace ::importMembers(imps: Set(PackageableElement )): Set(PackageableElement );

   importMembers = self.excludeCollisions(imps)->select(imp | self.ownedMember->forAll(mem |mem.imp.isDistinguishableFrom(mem, self)))

   [4] The query excludeCollisions() excludes from a set of PackageableElement s any that would not be distinguishable from each other in this namespace.

   Namespace ::excludeCollisions(imps: Set(PackageableElement s)): Set(PackageableElement s);

   excludeCollisions = imps->reject(imp1 | imps.exists(imp2 | not imp1.isDistinguishableFrom(imp2, self)))


   A namespace provides a container for named elements. It provides a means for resolving composite names, such as name1::name2::name3. The member association identifies all named elements in a namespace called N that can be referred to by a composite name of the form N::<x>. Note that this is different from all of the names that can be referred to unqualified within N, because that set also includes all unhidden members of enclosing namespaces.

   Named elements may appear within a namespace according to rules that specify how one named element is distinguishable from another. The default rule is that two elements are distinguishable if they have unrelated types, or related types but different names. This rule may be overridden for particular cases, such as operations that are distinguished by their signature.

   The ownedRule constraints for a Namespace represent well formedness rules for the constrained elements. These constraints are evaluated when determining if the model elements are well formed.


   No additional notation. Concrete subclasses will define their own specific notation.