Expressing pattern constraints

 

Defining pattern constraints

Pattern constraints are used to define the UML properties of the elements that make up the pattern solution. These constraints are checked by the pattern's application elements, thereby guaranteeing that the pattern will be correctly applied.

 

Pattern constraints are boolean expressions expressed in Objecteering's J language. They must be checked, in order for the pattern to be run.

 

To express a pattern constraint, the parameter element must first be selected either in the pattern's specification diagram or in the UML explorer, and then the J boolean expression entered in the “Pattern constraint” field of the “MDA” tab of the auxiliary window, as shown in Figure 154 below.

 

Figure 154. Example of a pattern constraint used in the “Observer” pattern

 

The new specification class diagram belonging to the “Observer” pattern is shown in Figure 154. The pattern constraint associated with the “update” parameter specifies that this parameter's substitution operation must be abstract (the “IsAbstract” UML property is true), and indicates that its visibility must be “Public. This is because it is going to be used by the “notify()” method in “Subject”.

 

If all the constraints used in a pattern are not checked when the pattern is applied, the pattern cannot be run. An error message appears, indicating the constraint that has not been respected, and the application of the pattern is cancelled.

 

Note:      The user can deactivate the pattern constraint check requirement, by unchecking the “Apply pattern constraints” tickbox in the “Pattern application” window shown in Figure 145 (please see “Applying patterns”).