Inheritance and Polymorphism

Templates are defined on a particular metaclass in a language definition file or extension and are inherited by and available to the children of the metaclass. For example, a template defined on the Classifier metaclass is available to templates or generated files defined on the Class and Interface metaclasses.

GTL supports the following OO concepts as part of inheritance:

You can define the same template multiple times in the hierarchy of a language definition file and extensions files, and PowerDesigner will resolve it using inheritance rules. For example, the myLang OOM language definition file and the myExtension extension file each contain a template %t% defined on each of the Classifier and Class metaclasses:

myLang Language Definition File myExtension Extension File
  • Classifier:
    • myFile generated file
    • %t% template
  • Class:
    • %t% template
  • Classifier:
    • myOtherFile generated file
    • %t% template
  • Class:
    • %t% template

The Class and Interface metaclasses both inherit from the Classifier metaclass, and each will generate a myFile and a myOtherFile.

The following template calls are possible in myLang/Classifier/myFile (which cannot access the templates in myExtension):
Template Call in myFile Template Called

%t% or

%myLang::t%

myLang/Class/t

%Classifier::t% or

%myLang::Classifier::t%

myLang/Classifier/t
The following template calls are possible in myExtension/Classifier/myOtherFile (which can access both its own templates and those in myLang):
Template Call in myOtherFile Template Called

%t% or

%myExtension::t%

myExtension/Class/t

%Classifier::t% or

%myExtension::Classifier::t%

myExtension/Classifier/t

%myLang::t% or

%myLang::Class::t%

myLang/Class/t

%myLang::Classifier::t%

myLang/Classifier/t
Note: For an extension file to reach templates defined in a language definition file, the Complement language generation property in the extension must be selected (see Extension File Properties).