Previous UML Classes Table of Contents UML Packages Next


17.5.7 Classifier

Templates


   Issue 8527 - reword for clarity

   Classifier is defined to be a kind of templateable element so that a classifier can be parameterized. It is also defined to be a kind of parameterable element so that a classifier can be a formal template parameter.

*Generalizations

   

    ParameterableElement (from Templates) on page 647

   

    TemplateableElement (from Templates) on page 649

   

    Classifier (from Kernel , Dependencies , PowerTypes ) on page 51 (merge increment)

   Description

Issue 8527 -insert commas as appropriate

   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 UseCases ) 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

   • ownedSignature : RedefinableTemplateSignature[0..1] The optional template signature specifying the formal template parameters. Subsets Element::ownedElement.

Issue 9110 - rename ‘parameter’ to ‘templateParameter’ and adjust constraint

   • templateParameter : ParameterableElement [0..1] The template parameter that exposes this element as a formal parameter. Redefines ParameterableElement::templateParameter.

   Constraints

   No additional constraints

   Additional Operations

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

   Classifier::isTemplate() : Boolean;

   isTemplate = oclAsType(TemplatableElement).isTemplate() or general->exists(g | g.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 that 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).

Issue 8527 - remove last sentence of paragraph

   A collaboration template will typically have the types of its parts as class template parameters. Consider the Collaboration in Figure 9.11 on page 177. This Collaboration can be bound from a Collaboration template of the form found in Figure 17.23, by means of the binding described in Figure 17.24.

   A bound Collaboration is not the same as a CollaborationUse ; in fact, parameterized Collaborations (and binding) cannot express what CollaborationUse s can. Consider the Sale Collaboration in Figure 9.13 on page 179. It is defined by means of two parts (Buyer and Seller) representing roles in this collaboration. The two CollaborationUse s wholesale and retail in Figure 9.14 on page 180 cannot be defined as bound Collaborations .

Issue 8527 - fix typos and some stylistic stuff

   A bound Collaboration is a Collaboration, while a CollaborationUse is not. A CollaborationUse is defined by means of RoleBindings, binding parts in a Collaboration (here Buyer and Seller) to parts in another classifier (here broker, producer, and consumer in BrokeredSale) 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. 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 9.14 on page 180. Parameters, by their 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 the classifier template parameter:

   

   has a generalization, then an actual classifier must have generalization with the same general classifier.

   

   has a substitution, then an actual classifier must have a substitution with the same contract.

   

   has neither a generalization nor a substitution, then an actual classifier can be any classifier.

   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> [‘:’ <attr-type>] [‘[‘<multiplicity> ‘]’] [‘=’ <default>][‘{‘<attr-property> [‘,’<attr-property>]* ‘}’]

   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) that substitutes the Address for T and 3 for k.

Figure 17.19 -Template Class and Bound Class

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


   Figure 17.20 - Anonymous Bound Class

   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.

Figure 17.21 - Template Class with a constrained class parameter

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

   DieselCar : Car<CarEngine -> DieselEngine, n -> 2>

   Figure 17.22 - Bound Class

   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.

Figure 17.23 - Template Collaboration

   ObserverPattern


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

   Observer



   ObserverPattern<SubjectType -> CallQueue, ObserverType -> SlidingBarIcon>



   Figure 17.24 - Bound Collaboration