Previous UML Classes Table of Contents UML Packages Next


17.5.2 TemplateableElement

Templates


   A templateable element is an element that can optionally be defined as a template and bound to other templates.

*Generalizations

   

    Element (from Kernel ) on page 63

   Description

   TemplateableElement may contain a template signature that specifies the formal template parameters. A TemplateableElement that contains a template signature is often referred to as a template.

   TemplateableElement may contain bindings to templates that describe how the templateable element is constructed by replacing the formal template parameters with actual parameters. A TemplateableElement containing bindings is often referred to as a bound element.

   Attributes

   No additional attributes

   Associations

Issue 8511 - add subsets constraint to ‘templateBinding’ and other editorial fixes

   • ownedTemplateSignature : TemplateSignature[0..1] The optional template signature specifying the formal template parameters. {Subsets Element::ownedElement}

   • templateBinding : TemplateBinding[*] The optional bindings from this element to templates. {Subsets Element::ownedElement}

   Constraints

   No additional constraints

   Additional Operations

   [1] The query parameterableElements() returns the set of elements that may be used as the parametered elements for a template parameter of this templateable element. By default, this set includes all the owned elements. Subclasses may override this operation if they choose to restrict the set of parameterable elements.

   TemplateableElement::parameterableElements() : Set(ParameterableElement);parameterableElements = allOwnedElements->select(oclIsKindOf(ParameterableElement))

   [2] The query isTemplate() returns whether this templateable element is actually a template.

   TemplateableElement::isTemplate() : Boolean;isTemplate = ownedSignature->notEmpty()

   Semantics

   A TemplateableElement that has a template signature is a specification of a template. A template is a parameterized element that can be used to generate other model elements using TemplateBinding relationships. The template parameters for the template signature specify the formal parameters that will be substituted by actual parameters (or the default) in a binding.

   A template parameter is defined in the namespace of the template, but the template parameter represents a model element that is defined in the context of the binding.

   A templateable element can be bound to other templates. This is represented by the bound element having bindings to the template signatures of the target templates. In a canonical model a bound element does not explicitly contain the model elements implied by expanding the templates it binds to, since those expansions are regarded as derived. The semantics and well-formedness rules for the bound element must be evaluated as if the bindings were expanded with the substitutions of actual elements for formal parameters.

   The semantics of a binding relationship is equivalent to the model elements that would result from copying the contents of the template into the bound element, replacing any elements exposed as a template parameter with the corresponding element(s) specified as actual parameters in this binding.

   A bound element may have multiple bindings, possibly to the same template. In addition, the bound element may contain elements other than the bindings. The specific details of how the expansions of multiple bindings, and any other elements owned by the bound element, are combined together to fully specify the bound element are found in the subclasses of TemplateableElement. The general principle is that one evaluates the bindings in isolation to produce intermediate results (one for each binding), which are then merged to produce the final result. It is the way the merging is done that is specific to each kind of templateable element.

   A templateable element may contain both a template signature and bindings. Thus a templateable element may be both a template and a bound element.

   A template cannot be used in the same manner as a non-template element of the same kind. The template element can only be used to generate bound elements (e.g., a template class cannot be used as the type of a typed element) or as part of the specification of another template (e.g., a template class may specialize another template class).

   A bound (non-template) element is an ordinary element and can be used in the same manner as a non-bound (and non-template) element of the same kind. For example, a bound class may be used as the type of a typed element.

   Notation

   If a TemplateableElement has template parameters, a small dashed rectangle is superimposed on the symbol for the templateable element, typically on the upper right-hand corner of the notation (if possible). The dashed rectangle contains a list of the formal template parameters. The parameter list must not be empty, although it might be suppressed in the presentation. Any other compartments in the notation of the templateable element will appear as normal.

   The formal template parameter list may be shown as a comma-separated list, or it may be one formal template parameter per line. See TemplateParameter for the general syntax of each template parameter.

   A bound element has the same graphical notation as other elements of that kind. Each binding is shown using the notation described under TemplateBinding.

   Presentation Options

   An alternative presentation for the bindings for a bound element is to include the binding information within the notation for the bound element. Typically the name compartment would be extended to contain a string with the following syntax: <element-name> ‘:’ <binding-expression> [‘,’ <binding-expression>]* <binding-expression> ::= <template-element-name> ‘<‘ <template-parameter-substitution> [‘,’<template-parameter-substitution]* ‘>’ and <template-parameter-substitution> is defined in TemplateBinding (from Templates).

   Examples

Issue 8511 - add complete cross-references

   For examples of templates, the reader is referred to those sections that deal with specializations of TemplateableElement, in particular ClassifierTemplates on page 656 and PackageTemplates on page 664.