Templates


The Templates package specifies how both Classifiers, Packages and Operations can be parameterized with Classifier, ValueSpecification and Feature (Property and Operation) template parameters. The package introduces mechanisms for defining templates, template parameters, and bound elements in general, and the specialization of these for classifiers and packages.

Classifier, package and operation templates were covered in 1.x in the sense that any model element could be templateable. This new metamodel restricts the templateable elements to those for which it is meaningful to have template parameters.

Templates




ParameterableElement

A parameterable element is an element that can be exposed as a formal template parameter for a template, or specified as an actual parameter in a binding of a template.

Description

A ParameterableElement can be referenced by a TemplateParameter when defining a formal template parameter for a template. A ParameterableElement can be referenced by a TemplateParameterSubstitution when used as an actual parameter in a binding of a template.

ParameterableElement is an abstract metaclass.

Attributes

No additional attributes

Associations
Constraints

No additional constraints.

Additional Operations

[1] The query isCompatibleWith() determines if this parameterable element is compatible with the specified parameterable element. By default parameterable element P is compatible with parameterable element Q if the kind of P is the same or a subtype as the kind of Q. Subclasses should override this operation to specify different compatibility constraints.
ParameterableElement::isCompatibleWith(p : ParameterableElement) : Boolean;
isCompatibleWith = p->oclIsKindOf(self.oclType)

[2] The query isTemplateParameter() determines if this parameterable element is exposed as a formal template parameter.

ParameterableElement::isTemplateParameter() : Boolean;
isTemplateParameter = parameter->notEmpty()

Semantics

A ParameterableElement may be part of the definition of a template parameter. The ParameterableElement is used to constrain the actual arguments that may be specified for this template parameter in a binding of the template.

A ParameterableElement exposed as a template parameter can be used in the template as any other element of this kind defined in the namespace of the template, e.g. a classifier template parameter can be used as the type of typed elements.

In a element bound to the template, any use of the template parameter will be substituted by the use of the actual parameter.

If a ParameterableElement is exposed as a template parameter, then the parameterable element is only meaningful within the template (it may not be used in other parts of the model).

Semantic Variation Points

The enforcement of template parameter constraints is a semantic variation point:


Notation

See TemplateParameter for a description of the notation for exposing a ParameterableElement as a formal parameter of a template.

See TemplateBinding for a description of the notation for using a ParameterableElement as an actual parameter in a binding of a template.

Within these notations, the parameterable element is typically shown as the name of the parametered element (if that element is a named element).

Examples

See TemplateParameter.

TemplateableElement

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

Description

TemplateableElement may contain a template signature which 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
Constraints

No additional constraints.

Additional Operations

[1] The query getParameterableElements() returns the set of elements that may be used as the parametered element for a template parameter if 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::getParameterableElements() : Set(ParameterableElement);

getParameterableElements = 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 which 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 subsititutions 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-list

where binding-expression-list is a comma-separated list of binding-expression defined to be:

template-element-name `<` {template-parameter-substitution}* `>'
and template-parameter-substitution is defined in TemplateBinding.

Examples

For examples of templates, the reader is referred to those sections which deal with specializations of TemplateableElement, in particular ClassifierTemplate and PackageTemplate.

TemplateBinding


A template binding represents a relationship between a templateable element and a template. A template binding specifies the substitutions of actual parameters for the formal parameters of the template.

Description

TemplateBinding is a directed relationship from a bound templateable element to the template signature of the target template. A TemplateBinding owns a set of template parameter substitutions.

Attributes

No additional attributes.

Associations
Constraints

[1] Each parameter substitution must refer to a formal template parameter of the target template signature.

parameterSubstitution->forAll(b | template.parameter->includes(b.formal))

[2] A binding contains at most one parameter substitution for each formal template parameter of the target template signature.

template.parameter->forAll(p | parameterSubstitution->select(b | b.formal = p)->size() <= 1)

Semantics

The presence of a TemplateBinding relationship implies the same semantics as if the contents of the template owning the target template signature were copied into the bound element, substituting any elements exposed as formal template parameters by the corresponding elements specified as actual parameters in this binding. If no actual parameter is specified in this binding for a formal parameter, then the default element for that formal template parameter (if specified) is used.

Semantic Variation Points

It is a semantic variation point
In case of complete binding, the bound element may have its own formal template parameters, and these template parameters can be provided as actual parameters of the binding. In case of partial binding, the unbound formal template parameters are formal template parameters of the bound element.

Notation

A TemplateBinding is shown as a dashed arrow with the tail on the bound element and the arrowhead on the template and the keyword <<bind>>. The binding information is generally displayed as a comma-separated list of template parameter substitutions:

template-parameter-substitition : template-parameter-name `->' actual-template-parameter

where the syntax of template-parameter-name depends on the kind of parameteredElement for this template parameter substitution and of actual-template-parameter depend upon the kind of element. See ParameterableElement (and its subclasses).

Examples

For examples of templates, the reader is referred to those sections which deal with specializations of TemplateableElement, in particular ClassifierTemplate and PackageTemplate.

TemplateParameter


A template parameter exposes a parameterable element as a formal template parameter of a template.

Description

TemplateParameter references a ParameterableElement which is exposed as a formal template parameter in the containing template.

Attributes

No additional attributes

Associations

Constraints

[1] The default must be compatible with the formal template parameter.

default->notEmpty() implies default->isCompatibleWith(parameteredElement)

[2] The default can only be owned if the parametered element is not owned.

ownedDefault->notEmpty() implies ownedParameteredElement->isEmpty()

Semantics

A TemplateParameter references a ParameterableElement that is exposed as a formal template parameter in the containing template. This parameterable element is meaningful only within the template, or other templates that may have access to its internals (e.g. if the template supports specialization). The exposed parameterable element may not be used in other parts of the model. A TemplateParameter may own the exposed ParameterableElement in situations where that element is only referenced from within the template.

Each the exposed element constrains the elements that may be substituted as actual parameters in a binding.

A TemplateParameter may reference a ParameterableElement as the default for this formal parameter in any binding that does not provide an explicit substitution. The TemplateParameter may own this default ParameterableElement in situations where the exposed ParameterableElement is not owned by the TemplateParameter.

Notation

The general notation for a template parameter is a string displayed within the template parameter list for the template:

template-parameter ::= template-parameter-name [ `:` parameter-kind ] [`=' default]

where parameter-kind is the name of the metaclass for the exposed element. The syntax of template-parameter-name depends on the kind of parameteredElement for this template parameter substitution and of default depend upon the kind of element. See ParameterableElement (and its subclasses).

Examples

See TemplateableElement.

 TemplateParameterSubstitution

A template parameter substitution relates the actual parameter(s) to a formal template parameter as part of a template binding.

Description

TemplateParameterSubstitution associates one or more actual parameters with a formal template parameter within the context of a TemplateBinding.

Attributes

No additional attributes

Associations

Constraints

[1] The actual parameter must be compatible with the formal template parameter, e.g. the actual parameter for a class template parameter must be a class.

actual->forAll(a | a.isCompatibleWith(formal.parameteredElement))

Semantics

A TemplateParameterSubstitution specifies the set of actual parameters to be substituted for a formal template parameter within the context of a template binding.

Notation

See TemplateBinding.

Examples

See TemplateBinding.

TemplateSignature

A template signature bundles the set of formal template parameters for a templated element.

Description

A TemplateSignature is owned by a TemplateableElement and has one or more TemplateParameters that define the signature for binding this template. A TemplateSignature may reference a set of nested template signatures to reflect the hierarchical nature of a template.

Attributes

No additional attributes.

Associations
Constraints

[1] Parameters must own the elements they parameter or those elements must be owned by the element being templated.

templatedElement.ownedElement->includesAll(parameter.parameteredElement - parameter.ownedParameteredElement)

[2] parameter are the owned parameter.

parameter = ownedParameter

Semantics

A TemplateSignature specifies the set of formal template parameters for the associated templated element. The formal template parameters specify the elements that may be substituted in a binding of the template.

There are constraints on what may be parametered by a template parameter. Either the parameter owns the parametered element, or the element is owned, directly or indirectly, by the template. Subclasses of TemplateSignature can add additional rules constraining what a parameter can reference in the context of a particular kind of template.

Notation

See TemplateableElement for a description of how the template parameters are shown as part of the notation for the template.

Examples

See TemplateableElement.

ClassifierTemplates

The Classifier templates diagram specifies the abstract mechanisms that support defining classifier templates, bound classifiers, and classifier template parameters. Specific subclasses of Classifier must also specialize one or more of the abstract metaclasses defined in this diagram in order to expose these capabilities in a concrete manner.



Classifier (as specialized)

Classifier is defined to be a kind of templateable element so that a classifier can be parameterized, and as a kind of parameterable element so that a classifier that can be exposed as a formal template parameter, and provided as an actual parameter in a binding of a template.

Description

Classifier specializes Kernel::Classifier TemplateableElement and ParameterableElement to specify that a classifier can be parameterized, be exposed as a formal template parameter, and can be specified as an actual parameter in a binding of a template.

A classifier with template parameters is often called a template classifier, while a classifier with a binding is often called a bound classifier.

By virtue of Classifier being defined here, all subclasses of Classifier (such as Class, Collaboration, Component, Datatype, Interface, Signal and Use Cases) can be parameterized, bound and used as template parameters. The same holds for Behavior as a subclass of Class, and thereby all subclasses of Behavior (such as Activity, Interaction, Statemachine).

Attributes

No additional attributes.

Associations
Constraints

No additional constraints.

Additional Operations

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

Classifier::isTemplate() : Boolean;
isTemplate = TemplatableElement::isTemplate() or general->exists(isTemplate())

Semantics

Classifier in general

Classifier provides the abstract mechanism that can be specialized to support subclass of Classifiers to be templates, exposing subclasses of Classifier as formal template parameters, and as actual parameters in a binding of a template.

Classifier as a kind of templateable element provides the abstract mechanism that can be specialized by subclasses of  Classifier to support being defined as a template, or being bound to a template.

A bound classifier may have contents in addition to those of the template classifier. In this case the semantics are equivalent to inserting an anonymous general classifier which contains the contents, and the bound classifier is defined to be a specialization this anonymous general classifier. This supports the use of elements within the bound classifier as actual parameters in a binding.

A bound classifier may have multiple bindings. In this case the semantics are equivalent to inserting an anonymous general bound classifier for each binding, and specializing all these bound classifiers by this (formerly) bound classifier.

The formal template parameters for a classifier include all the formal template parameters of all the templates it specializes. For this reason the classifier may reference elements that are exposed as template parameters of the specializes templates.

Collaboration

A Collaboration supports the ability to be defined as a template. A collaboration may be defined to be bound from template collaboration(s).

A collaboration template will typically have the types of it parts as class template parameters. Consider the Collaboration in Figure 104 . This Collaboration can be bound from a Collaboration template of the form found in Figure 434, by means of the binding described in Figure 435. We have here used that the default kind of template parameter is a class, i.e., SubjectType and ObserverType are class template parameters.

A bound Collaboration is not the same as a CollaborationOccurrence; in fact, parameterized Collaborations (and binding) can not express what CollaborationOccurrences can. Consider the Sale Collaboration in Figure 107 . It is defined by means of two parts (Buyer and Seller) representing roles in this collaboration. The two CollaborationOccurrences 'wholesale' and `retail' in Figure 108 cannot be defined as bound Collaborations.

A bound Collaboration is a Collaboration, while a CollaborationOccurrence is not. A CollaborationOccurrence is defined by means of RoleBindings, binding parts in a Collaboration (here Buyer and Seller) to parts in another classifier (here broker, produce and consumer in NrokeredSale) with the semantics that the interaction described in Sale will occur between broker, producer and consumer. Binding eventual Buyer and Seller part template parameters (of a Sale Collaboration template) to broker and producer would just provide that the parts broker and producer are visible within the bound Sale Collaboration. And anyway, even if Sale had two part template parameters Buyer and Seller, it could not use these for defining an internal structure as is the case in Figure 108 . Parameters, by the very nature, represent elements that are defined `outside' a Collaboration template and can therefore not be parts of an internal structure of the Collaboration template.

Semantic Variation Points

If template parameter constraints apply, then the actual classifier is constrained as follows:

If template parameter constraints do not apply, then an actual classifier can be any classifier.

Notation

See ClassifierTemplateParameter for a description of how a parameterable classifier is displayed as a formal template parameter.

See TemplateableElement for the general notation for displaying a template and a bound element.

When a bound classifier is used directly as the type of an attribute, then <classifier expression> acts as the type of the attribute in the notation for an attribute:

[visibility] [/] name [: type] [multiplicity] [= default] [{ property-string }]

When a bound classifier is used directly as the type of a part, then <classifier-expression> acts as the classname of the part in the notation for a part:

{{ [ name ] `:' classname } | name } [ `[` multiplicity `]' ]

Presentation Options

Collaboration extends the presentation option for bound elements described under TemplateableElement so that the binding information can be displayed in the internal structure compartment.

Examples

Class templates

As Classifier is an abstract class, the following example is an example of concrete subclass (Class) of Classifier being a template.

The example shows a class template (named FArray) with two formal template parameters. The first formal template parameter (named T) is an unconstrained class template parameter. The second formal template parameter (named k) is an integer expression template parameter that has a default of 10. There is also a bound class (named AddressList) which substitutes the Address for T and 3 for k.



The following figure shows an anonymous bound class that substitutes the Point class for T. Since there is to substitution for k, the default (10) will be used.



The following figure shows a template class (named Car) with two formal template parameters. The first formal template parameter (named CarEngine) is a class template parameter that is constrained to conform to the Engine class. The second formal template parameter (named n) is an integer expression template parameter.



The following figure shows a bound class (named DieselCar) that binds CarEngine to DieselEngine and n to 2.



Collaboration templates

The example below shows a collaboration template (named ObserverPattern) with two formal template parameters (named SubjectType and ObserverType). Both formal template parameters are unconstrained class template parameters.



The following figure shows a bound collaboration (named Observer) which substitutes CallQueue for SubjectType, and SlidingBarIcon for ObserverType.


ClassifierTemplateParameter

A classifier template parameter exposes a classifier as a formal template parameter.

Description

ClassifierTemplateParameter is a template parameter where the parametered element is a Classifier in its capacity of being a kind of ParameterableElement.

Attributes
Associations
Constraints

No additional constraints.

Semantics

See Classifier for additional semantics related to the compatibility of actual and formal classifier parameters.

Notation

A classifier template parameter extends the notation for a template parameter to include an optional type constraint:

classifier-template-parameter ::= parameter [ `:` parameter-kind ] [`>' constraint] [`=' default]
parameter ::= parameter-name
constraint ::= [`{contract }'] classifier-name
default ::= classifier-name

The parameter-kind indicates the metaclass of the parametered element. It may be suppressed if it is `class'.

The classifier-name of constraint designates the type constraint of the parameter, which reflects the general classifier for the parametered element for this template parameter. The `contract' option indicates that allowsSubstitutable is true, meaning the actual parameter must be a classifier that may substitute for the classifier designated by the classifier-name.

A classifier template parameter with a constraint but without `contract' indicates that the actual classifier must be a specialization of the classifier designated by the classifier-name.

Examples

See Classifier.

 RedefinableTemplateSignature

A redefinable template signature supports the addition of formal template parameters in a specialization of a template classifier.

Description

RedefinableTemplateSignature specializes both TemplateSignature and RedefinableElement in order to allow the addition of new formal template parameters in the context of a specializing template Classifier.

Attributes

No additional attributes.

Associations
Constraints

[1] The inherited parameters are the parameters of the extended template signature.

inheritedParameter = if extendedSignature->isEmpty() then Set{} else extendedSignature.parameter endif

Additional Operations

[1] The query isConsistentWith() specifies, for any two RedefinableTemplateSignatures in a context in which redefinition is possible, whether redefinition would be logically consistent. A redefining template signature is always consistent with a redefined template signature, since redefinition only adds new formal parameters.

RedefineableTemplateSignature::isConsistentWith(redefinee: RedefinableElement): Boolean;
pre: redefinee.isRedefinitionContextValid(self)
        isConsistentWith = redefinee.oclIsKindOf(RedefineableTemplateSignature)

Semantics

A RedefinableTemplateSignature may extend an inherited template signature in order to specify additional formal template parameters that apply within the templateable classifier that owns this RedefinableTemplateSignature. All the formal template parameters of the extended signatures are included as formal template parameters of the extending signature, along with any parameters locally specified for the extending signature.

Notation

Notation as for redefinition in general.

PackageTemplates

The Package templates diagram supports the specification of template packages and package template parameters.



Package (as specialized)

Description

Package specializes TemplateableElement and PackageableElement specializes ParameterableElement to specify that a package can be used as a template and a PackageableElement as a template parameter.

Attributes

No additional attributes

Associations

No additional associations.

Constraints

No additional constraints.

Semantics

A Package supports the ability to be defined as a template, and PackageableElements may, therefore, be parametered in a package template. A package template parameter may refer to any element owned or used by the package template, or templates nested within it, and so on recursively. That is, there are no special rules concerning how

A package may be defined to be bound to one or more template packages. The semantics for these bindings is as described in the general case, with the exception that we need to spell out the rules for merging the results of multiple bindings. In that case, the effect is the same as taking the intermediate results and merging them into the eventual result using package merge. This is illustrated by the example below.

Notation

See TemplateableElement for a description of the general notation that is defined to support these added capabilities.

Examples

The example below shows a package template (named ResourceAllocation) with three formal template parameters. All three formal template parameters (named Resource, ResourceKind, and System) are unconstrained class template parameters. There is also a bound package (named CarRental) which substitutes Car for Resource, CarSpec for ResourceKind, and CarRentalSystem for System.



NameExpressions

The NameExpressions diagram supports the use of string expressions to specify the name of a named element.


 

NamedElement (as specialized)

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.

Description

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

Attributes

No additional attributes.

Associations
Constraints

[1] The name expression must be a string expression.

nameExpression->notEmpty() implies nameExpression.type = String

[2] The name is derived from the name expression only in the case that the nameExpression is a string literal.

nameExpression.oclIsKindOf(LiteralString) implies name = nameExpression.value

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 439.

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

With alias: Both the the string expression and the alias is 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) which are parametered in the template are shown between angle brackets (see section on ValueSpecificationTemplateParameters).

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.






Operation (as specialized)

Description

Class specializes TemplateableElement in order to support specification of template operations and bound operations.

Attributes

No additional attributes

Associations

No additional associations.

Constraints

No additional constraints.

Semantics

An Operation supports the ability to be defined as a template. An operation may be defined to be bound to template operation(s).

Notation

The template parameters and template parameter binding of a template operation are two lists in between the name of the operation and the parameters of the operation

visibility name `<` template-parameter-list `>' `<<`binding-expression-list `>>'`( ` parameter-list `)' `:' property-string

where template-parameter-list is a comma-separated list of template-parameter.

OperationTemplateParameters

The Operation template parameters diagram supports the specification of operation template parameters.

Parameterab leElement



Operation (as specialized)

Description

Operation specializes ParameterableElement to specify that an operation can be exposed as a formal template parameter, and provided as an actual parameter in a binding of a template.

Attributes

No additional attributes

Associations
Constraints

No additional constraints.

Semantics

An Operation may be exposed by a template as a formal template parameter. Within a template classifier an operation template parameter may be used as any other operation defined in an enclosing namespace. Any references to the operation template parameter within the template will end up being a reference to the actual operation in the bound classifier. For example, a call to the operation template parameter will be a call to the actual operation.

Notation

See OperationTemplateParameter for a description of the general notation that is defined to support these added capabilities.

Within the notation for formal template parameters and template parameter bindings, an operation is shown as operation-name `(` operation-parameters `)'.

OperationTemplateParameter

An operation template parameter exposes an operation as a formal parameter for a template.

Description

OperationTemplateParameter is a template parameter where the parametered element is an Operation.

Attributes

No additional attributes.

Associations
Constraints

No additional constraints.

Semantics

See Operation for additional semantics related to the compatibility of actual and formal operation parameters.

Notation

An operation template parameter extends the notation for a template parameter to include the parameters for the operation:

operation-template-parameter ::= parameter [ `:` parameter-kind ] [`=' default]
parameter ::= operation-name ( parameter-list )
default ::= operation-name ( parameter-list )

ConnectableElement template parameters

The Connectable element template parameters package supports the specification of ConnectableElement template parameters.



ConnectableElement (as specialized)

A connectable element may be exposed as a connectable element template parameter.

Description

ConnectableElement is the connectable element of a ConnectableElementTemplateParameter.

Attributes

No additional attributes.

Associations
Constraints

No additional constraints.

Semantics

No additional semantics.

Notation

No additional notation.

ConnectableElementTemplateParameter

A connectable element template parameter exposes a connectable element as a formal parameter for a template.

Description

ConnectableElementTemplateParameter is a template parameter where the parametered element is a ConnectableElement.

Attributes

No additional attributes.

Associations
Constraints

No additional constraints.

Semantics

No additional semantics.

Notation

No additional notation.

PropertyTemplateParameters

The Property template parameters diagram supports the specification of property template parameters.



Property (as specialized)

Description

Property specializes ParameterableElement to specify that a property can be exposed as a formal template parameter, and provided as an actual parameter in a binding of a template.

Attributes

No additional attributes

Associations

No additional associations.

Constraints

[1] A binding of an property template parameter representing an attribute must be to an attribute.

Additional Operations

[1] The query isCompatibleWith() determines if this parameterable element is compatible with the specified parameterable element. By default parameterable element P is compatible with parameterable element Q if the kind of P is the same or a subtype as the kind of Q. In addition, for properties, the type must be conformant with the type of the specified parameterable element.

Property::isCompatibleWith(p : ParameterableElement) : Boolean;
isCompatibleWith = p->oclIsKindOf(self.oclType) and self.type.conformsTo(p.oclAsType(TypedElement).type)

Semantics

A Property may be exposed by a template as a formal template parameter. Within a template a property template parameter may be used as any other property defined in an enclosing namespace. Any references to the property template parameter within the template will end up being a reference to the actual property in the bound element.

Notation

See ParameterableElement for a description of the general notation that is defined to support these added capabilities.

ValueSpecificationTemplateParameters

The ValueSpecification template parameters diagram supports the specification of value specification template parameters.



ValueSpecification (as specialized)

Description

ValueSpecification specializes ParameterableElement to specify that a value specification can be exposed as a formal template parameter, and provided as an actual parameter in a binding of a template.

Attributes

No additional attributes.

Associations
Constraints

No additional attributes.

Additional Operations

[1] The query isCompatibleWith() determines if this parameterable element is compatible with the specified parameterable element. By default parameterable element P is compatible with parameterable element Q if the kind of P is the same or a subtype as the kind of Q. In addition, for ValueSpecification, the type must be conformant with the type of the specified parameterable element.

Property::isCompatibleWith(p : ParameterableElement) : Boolean;
isCompatibleWith = p->oclIsKindOf(self.oclType) and self.type.conformsTo(p.oclAsType(TypedElement).type)

Semantics

The semantics is as in the general case. However, two aspects are worth commenting on. The first is to note that a value specification may be an expression with substructure (i.e. an instance of the Expression class), in which case a template parameter may expose a subexpression, not necessarily the whole expression itself. An example of this is given in Figure 432 where the paremetered element with label `n' appears within the expression `n+1'. Secondly, to note that by extending NamedElement to optionally own a name expression, strings that are part of these named expressions may be parametered.

Notation

Where a parametered ValueSpecification is used within an expression, the name of the parameter is used instead of any symbol (in case of an Expression) or value (in case of a Literal) would otherwise appear.