## Pattern

## Definition

A pattern is a solution to a recurrent generation problem. The objective is 1) to produce assets in series (code, frameworks, tools, etc.), 2) to customize a generation in order to fit project needs.

## Motivation

The motivation is to produce assets with systematism and with the ability to tailor this generation. The pattern features are the following:

- A pattern is an autonomous generation unit with parameters and methods which implement the pattern behavior.
- The pattern inheritance allows the definition of standard behaviors and the ability to customize them afterwards by specialization.
- The pattern delegation allows the ability to reuse existing patterns. The delegation can be a simple delegation or a delegation with a pattern context injection where the current pattern provides parameter values to the called pattern.
- A parameter is a resource and can be from any type, e.g. a model, a file directory, a plugin.
- A method conforms to a language specific to a concern, for instance to apply model-to-text transformations (e.g., with Jet). This language is identified by a pattern nature. A pattern nature is associated to a pattern engine. A pattern engine is able 1) to translate source code into an executable language, and 2) to execute it during an execution phase.

Figure 1. Generation Pattern GLobal View

## Structure

Pattern library. Patterns are organized in pattern libraries. A pattern library allows both classifying and defining pattern execution blocks.

Pattern. A pattern contains an ordered set of parameters, an ordered set of methods, local variables. A pattern can inherit from another pattern (simple inheritance) and can call other patterns.

Pattern Parameter. A pattern contains a set of parameters. A parameter has a name and type. A parameter type is a model element from an ecore amodel or a Java type.

A pattern parameter is associated to a query applied on a input resource.

The set of pattern parameters and their queries define a Cartesian product [P1 x P2 x ... x Pn]. At execution time, pattern methods are applied on each tuple of the query results. A pattern without parameter calls the pattern methods just one time.

Variables. A pattern can work with local variables. The variable type is a model element or a Java type.

Method. A method contains a description that conforms to a language (e.g., Jet). The most popular type of description is textual but it could be action semantics or an activity graph. A method can overload a method of a super-pattern. A method orchestration defines the order to apply methods and pattern calls at execution.

Pattern Inheritance. Pattern inheritance serves to inherit of parameter definition and methods. For the Cartesian product, the super-patterns are considered first. A super-pattern can be defined in another a pattern library than the current pattern's library, or in a library from a different Factory Component.

Pattern Call. A pattern call serves to reuse patterns.

- Case 1. The called pattern has no parameter. It is a simple pattern delegation.
- Case 2. The called pattern has parameters. It is a delegation and the called pattern applies queries on each parameter.
- Case 3. A pattern call with parameter injection. The parameters of the called pattern are initialized by the pattern caller.

## Process of translation and execution

Patterns are edited first (creation, update, deletion), processed to be executed, and executed.

Translation.Translation transforms the pattern and its methods toward a target language (e.g., Jet form) understandable by an engine (e.g., the Jet engine). When needed, the translated code is compiled.

Execution. At this step, the executable result of the translation is executed by an engine (e.g., the Jet model-to-text engine) according an execution strategy (e.g., pattern-oriented, resource-oriented strategies). The result of this execution is transmitted to a reporter.

Figure 3. Translation and Execution of Pattern