Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

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.

Reference:

The following table lists and briefly describes the 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

 

The second table lists templates used for generating code for languages that have 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

Topics:

Topic

Detail

See also

Further Information

The base templates form a hierarchy, which varies slightly across different programming languages. A typical template hierarchy relevant to a language like C# or Java (which do not have header files) is shown in the example diagram below. In this diagram the templates are modeled as Classes (in reality they 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
  • 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