Expressing pattern actions

 

Expressing a pattern's actions

When patterns are applied in development projects, certain model elements must be modified, while others have to be deleted. These modifications allow any redundancy between model elements and pattern solutions elements to be removed, and allow the modification of the state of certain elements, so that they will be compatible with the requirements of the pattern solution.

 

Patterns applied in MDA Modeler can modify and delete application model elements, by using the notion of pattern actions.

 

Actions are instructions coded in the J language, in correct syntax with the possibility of referencing pattern parameter values through the “<%” and “%>” strings. Pattern actions are defined when the pattern is specified and are run when the pattern is applied.

 

Expressing a modify action

To express a modify action, the element to be modified must be selected either in the pattern specification diagram or the UML explorer and then the J modification instructions entered in the “Pattern action” field of the “MDA” tab of the auxiliary window.

There is no particular format for expressing modification actions, as all the various coding possibilities provided by J code can be used. However, for frequent modification needs, we recommend that you use one or several J instructions in the following form:

 

set<Property> (expressionValue);

 

In this format:

·         “set<Property>” is the J method defined in Objecteering for the modification of an element's <Property> property.

·         “expressionValue” is an expression in the J language which returns the same type as the property which is to modified

 

Expressing a delete action

To express a delete action, you should simply select the element which is to be deleted in the pattern's specification diagram and then check the “To be removed” tickbox in the “MDA” tab of the auxiliary window.

 

Example of pattern actions

To illustrate the use of pattern actions, we are going to present the pattern example defined in Objecteering Java Developer named “Transform into a non-primivite class”. This pattern is used to transform an attribute in a class into an association between its class and the class of its type. More precisely, when the “Transform into a non-primitive class” pattern is applied, it:

·         deletes the attribute

·         creates an association between the attribute's class and its type class, with the same name and the same UML properties

·         transforms the type class into a non-primitive class

 

The specification class diagram of the “Transform into a non-primitive class” pattern is shown in Figure 155. The three actions defined on each of its elements (the “<%attribute%>” attribute, the “<%attribute%>” role and the “<%Type%>” class) are shown in Figure 156.

 

Figure 155. Example of the “Transform into a non-primitive class” pattern

 

In the case of the “Transform into a non primitive class” pattern, the actions defined are as follows:

·         A delete action on the “<%attribute%>” attribute

·         A modify action on the “<%attribute%>” association end

·         A modify action on the “<%Type%>" class

 

Figure 156. Example of pattern actions used in the “Transform into a non-primitive class” pattern