Prev | Next |
Base Templates
The Code Template Framework consists of a number of base templates. Each base template transforms particular aspects of the UML to corresponding parts of object-oriented languages.
The base templates form a hierarchy, which varies slightly across different programming languages. In a typical template hierarchy relevant to a language like C# or Java (which do not have header files) the templates can be modeled as Classes, but usually are just plain text. This hierarchy would be slightly more complicated for languages like C++ and Delphi, which have separate implementation templates.
Each of the base templates must be specialized to be of use in code engineering; in particular, each template is specialized for the supported languages (or 'products'). For example, there is a ClassBody template defined for C++, another for C#, another for Java, and so on; by specializing the templates, you can tailor the code generated for the corresponding UML entity.
Once the base templates are specialized for a given language, they can be further specialized based on:
- A Class's stereotype, or
- A feature's stereotype (where the feature can be an operation or attribute)
This type of specialization enables, for example, a C# operation that is stereotyped as «property» to have a different Operation Body template from an ordinary operation; the Operation Body template can then be specialized further, based on the Class stereotype.
Base templates used in the CTF
Template |
Description |
---|---|
Attribute |
A top-level template to generate member variables from UML attributes. |
Attribute Declaration |
Used by the Attribute template to generate a member variable declaration. |
Attribute Notes |
Used by the Attribute template to generate member variable notes. |
Class |
A top-level template for generating Classes from UML Classes. |
Class Base |
Used by the Class template to generate a base Class name in the inheritance list of a derived Class, where the base Class doesn't exist in the model. |
Class Body |
Used by the Class template to generate the body of a Class. |
Class Declaration |
Used by the Class template to generate the declaration of a Class. |
Class Interface |
Used by the Class template to generate an interface name in the inheritance list of a derived Class, where the interface doesn't exist in the model. |
Class Notes |
Used by the Class template to generate the Class notes. |
File |
A top-level template for generating the source file. For languages such as C++, this corresponds to the header file. |
Import Section |
Used in the File template to generate external dependencies. |
Linked Attribute |
A top-level template for generating attributes derived from UML Associations. |
Linked Attribute Notes |
Used by the Linked Attribute template to generate the attribute notes. |
Linked Attribute Declaration |
Used by the Linked Attribute template to generate the attribute declaration. |
Linked Class Base |
Used by the Class template to generate a base Class name in the inheritance list of a derived Class, for a Class element in the model that is a parent of the current Class. |
Linked Class Interface |
Used by the Class template to generate an Interface name in the inheritance list of a derived Class, for an Interface element in the model that is a parent of the current Class. |
Namespace |
A top-level template for generating namespaces from UML Packages (although not all languages have namespaces, this template can be used to generate an equivalent construct, such as Packages in Java). |
Namespace Body |
Used by the Namespace template to generate the body of a namespace. |
Namespace Declaration |
Used by the Namespace template to generate the namespace declaration. |
Operation |
A top-level template for generating operations from a UML Class's operations. |
Operation Body |
Used by the Operation template to generate the body of a UML operation. |
Operation Declaration |
Used by the Operation template to generate the operation declaration. |
Operation Notes |
Used by the Operation template to generate documentation for an operation. |
Parameter |
Used by the Operation Declaration template to generate parameters. |
Templates for generating code for languages with separate interface and implementation sections
Template |
Description |
---|---|
Class Impl |
A top-level template for generating the implementation of a Class. |
Class Body Impl |
Used by the Class Impl template to generate the implementation of Class members. |
File Impl |
A top-level template for generating the implementation file. |
File Notes Impl |
Used by the File Impl template to generate notes in the source file. |
Import Section Impl |
Used by the File Impl template to generate external dependencies. |
Operation Impl |
A top-level template for generating operations from a UML Class's operations. |
Operation Body Impl |
Used by the Operation template to generate the body of a UML operation. |
Operation Declaration Impl |
Used by the Operation template to generate the operation declaration. |
Operation Notes Impl |
Used by the Operation template to generate documentation for an operation. |
Learn more