In real world situations there is an additional usage of TemplateFunctions: TempalteFunctions are used to improve the accessibility of the MetaModel from within the Templates. Useful Function within a Template could for example be:
- determineType
- determineImport
- evaluateTypeAnnotation
- determineReferencedTypes
- etc.
Experience shows, that TemplateFunctions grow over time and that the structures choosen in the beginning seem to be less than optimal. Therefor the following recommendation describes a proven structure on how to manage TemplateFunctions:
I would recommend to start from the beginning with at least three diffenerent Types of TemplateFunctions:
- Specfic TempalteFunctions: specific functions are used only in the template they are associated with
- Common TempalteFunctions: common functions are used in some or all templates, but are template related
- MetaModel TemplateFunctions: meta model functions are used in all templates (and maybe even in the meta model itself) and provide additional value functions on top of the meta model
This recommendation is a good starting point to get the structure of TemplateFunctions right from the very beginning. Also this structure give support in the following areas:
- Collaboration: responsibility for different TemplateFunctions can be distributed on different roles (e.g. Model-Architect defining the Meta-Model, Application-Architect defining common functions, Application-Developer working on his own specific templates
- Granularity and Separation of Concern: focus on a limitd scope is posiible
- Governance and Artefact Life-Cycle: meta model functions will change less frequently than template specific functions
Hopefully this recommendation will help you get the TempalteFunction structure right from the beginning.