Previous UML Classes Table of Contents UML Packages Next


17.5.12 NamedElement

Templates


   A named element is extended to support using a string expression to specify its name. This allows names of model elements to involve template parameters. The actual name is evaluated from the string expression only when it is sensible to do so (e.g., when a template is bound).

*Generalizations

   

    NamedElement (from Kernel , Dependencies ) on page 99 (merge increment)

   Description

   NamedElement specializes Kernel ::NamedElement and adds a composition association to Expression.

   Attributes

   No additional attributes

   Associations

Issue 8529 - fix type of nameExpression to StringExpression and add subsets constraint

   • nameExpression : StringExpression [0..1]The string expression used to define the name of this named element. (Subsets

   Element::ownedElement}

   Constraints

   No additional constraints

   Semantics

   A NamedElement may, in addition to a name, be associated with a string expression. This expression is used to calculate the name in the special case when it is a string literal. This allows string expressions, whose sub expressions may be parametered elements, to be associated with named elements in a template. When a template is bound, the sub expressions are substituted with the actuals substituted for the template parameters. In many cases, the resultant expression will be a string literal (if we assume that a concatenation of string literals is itself a string literal), in which case this will provide the name of the named element.

   A NamedElement may have both a name and a name expression associated with it. In which case, the name can be used as an alias for the named element, which will surface, for example, in an OCL string. This avoids the need to use string expressions in surface notation, which is often cumbersome, although it doesn’t preclude it.

   Notation

   The expression associated with a named element can be shown in two ways, depending on whether an alias is required or not. Both notations are illustrated in Figure 17.28.

   

   No alias: The string expression appears as the name of the model element.

Issue 8529 -replace ‘is’ with ‘are’

   

   With alias: Both the string expression and the alias are shown wherever the name usually appears. The alias is given first and the string expression underneath.

   In both cases the string expression appears between $ signs. The specification of expressions in UML supports the use of alternative string expression languages in the abstract syntax -they have to have String as their type and can be some structure of operator expressions with operands. The notation for this is discussed in the section on Expressions. In the context of templates, sub expressions of a string expression (usually string literals) that are parametered in the template are shown between angle brackets (see section on ValueSpecification TemplateParameters).

   Examples

   The figure shows a modified version of the ResourceAllocation package template where the first two formal template parameters have been changed to be string expression parameters. These formal template parameters are used within the package template to name some of the classes and association ends. The figure also shows a bound package (named TrainingAdmin) that has two bindings to this ResourceAllocation template. The first binding substitutes the string Instructor for Resource, the string Qualification for ResourceKind, and the class TrainingAdminSystem for System. The second binding substitutes the string Facility for Resource, the string FacilitySpecification for ResourceKind, and the class TrainingAdminSystem is again substituted for System.

   The result of the binding includes both classes Instructor, Qualification, and InstructorAllocation as well as classes Facility, FacilitySpecification, and FacilityAllocation. The associations are similarly replicated. Note that Request will have two attributes derived from the single <resourceKind> attribute (shown here by an arrow), namely qualification and facilitySpecification.

Figure 17.28 - Template Package with string parameters