Chapter 9 Generation Reference Guide (GTL)


Defining polymorphism

Templates are dynamically bound. In other words, the choice of the template to be evaluated is made at translation-time based on the type of object it is applied to. This mechanism is comparable to the virtual method invocation mechanism found in object-oriented languages.

Polymorphism is achieved by allowing template redefinition in derived classes. For instance, it is useful in Java to define Generated Files on the classifier. Polymorphism allows template code defined on a classifier to use templates defined on its children (class, interface), the template being used does not have to be defined on the parent metaclass. Coupled with inheritance, this feature helps you share template code.

Example


The content of %definition% is the one defined in Classifier for an interface, and the one defined in Class for a class.

 


Copyright (C) 2005. Sybase Inc. All rights reserved.