Template parameters and arguments

In UML models, template parameters are formal parameters that once bound to actual values, called template arguments, make templates usable model elements.

You can use template parameters to create general definitions of particular types of template. For example, when you add template parameters to a class, it becomes a template class (sometimes called a parameterized class). Using a template class as a general pattern, you can create a group of classes that use template parameters to define more specific behavior.

Every template parameter must have a name and a type. The name of the parameter must be unique in the template parameter list. The type is a reference to a type of model element (for example, a class, an interface, or an attribute) or to a primitive data type (for example, an Integer or a String). A template parameter can take a default value if you do not specify a template argument when you bind the parameter to the template.

As you bind a model element to a template, you assign values (called template arguments) to the template parameters. Template arguments replace template parameters in model elements that you bind to a template. This action creates a new model element that has the structure of the template and that uses the values of its template arguments.

The syntax of a template parameter is name : type.

The notation for a template parameter in the diagram editor is a box with a dashed border in the upper right corner of a classifier shape. The Model Explorer view lists template parameters under the classifier for which they are defined.

Template parameters in the diagram editor

Template Parameters in the Model Explorer view

A Cart class has a rectangle displayed in the upper right corner. The rectangle contains two lines of text. On the first line are the words Class > Cart; on the section line are the words Class > Class. A small solid red circle is displayed at the beginning of each line. A tree structure displays the hierarchy of the class and corresponding template parameters. At the top is the Cart class displayed as the class icon followed by the word Cart. The class icon appears as a green circle containing a white capital C. Below that and indented in one level is the class icon with a small solid red circle at the topic, followed by the words TemplateSignature. Below that are the two parameters: Class > Cart and Class > Class, each on separate lines and indented in one level.
Related tasks
Modifying parameters, literals, and signals in classifiers
Modifying template parameters and arguments
Adding template parameters to classes and collaborations
Deleting template parameters
Feedback
(C) Copyright IBM Corporation 2004, 2005. All Rights Reserved.