Modeling pattern solutions

 

Modeling a pattern's solution

Before being able to model a pattern's solution, the package template used to store the pattern's specification must already exist (for further information, please see “Creating patterns”).

The first step in the modeling of a pattern's solution is to add the different elements which make up the structure of the pattern to the class diagram associated with the pattern. Objecteering MDA Modeler supports the following modeling elements:

·         packages

·         classes

·         data types

·         enumerations

·         interfaces

·         operations

·         attributes

·         associations

·         generalization

·         implementations

·         various associated notes, constraints, tagged values and stereotypes

 

Note:      For pattern designers who are not overly familiar with patterns, we recommend that you consult the various published catalogs available, for example, GOF.

 

Defining a pattern parameter

The  button in the “MDA” tab is used to declare an element as being a pattern parameter. Declarations are made in the form “<%element_name_parameter%>” and by associating the {PatternParameter} tagged value to the element in question. The “Make Parameter” window (Figure 149) allows the pattern designer to change the name of the parameter element, specify its substitution multiplicity and modify its description. The substitution multiplicity and description are used when the pattern is applied.

 

Figure 149. Defining a pattern parameter

 

Removing a pattern parameter

The  button in the “MDA” tab of the auxiliary window is used to delete the declaration of a parameter from the pattern. The element retakes its original name without the “<%” and “%>” characters and no longer bears the {PatternParameter} tagged value.

 

Referencing a pattern parameter

The  button in the “MDA” tab of the auxiliary window allows you to use the name of a parameter element that has already been declared. When the pattern designer clicks on this button, the “Reference a parameter” window (Figure 150) appears, allowing him to select an existing parameter and to complete it with a prefix and/or a suffix.

 

Figure 150. The “Reference a parameter” window

 

Removing a pattern parameter reference

The  button in the “MDA” tab of the auxiliary window is used to delete a reference to a pattern parameter. The element retakes its original name without the “<%” and “%>” characters. Please note that pattern parameters can be referenced within textual notes or code notes.

 

Adding an external reference

The  button in the “MDA” tab of the auxiliary window is used to add a reference to an element outside the pattern definition package.

 

Where the modeling of a pattern requires the use or implementation of elements (classes, interfaces, data types or enumerations) common to several development projects (for example, Java interfaces), external references are defined in the definition template package from the pattern towards to the elements in question. References outside the context of the pattern definition model are created by adding an element (class, interface, data type or enumeration) possibly using the pattern specification diagram or UML explorer, and then clicking on the  button. The window shown in Figure 151 then appears, allowing the pattern designer to drag and drop the element into the reference dropzone.

 

Figure 151. The "Add external reference" window

 

The example of the modeling of the “Observer” pattern shown in Figure 152 uses the “update” service of the “java.util.Observer” predefined interface, and the “notifyObservers” and “addObserver” services of the “java.util.Observable” class, and contains two external references:

·         the “Observable” class references the “java.util.Observable” class

·         the “Observer” interface references the “java.util.Observer” interface

 

Figure 152. Example of the modeling of the “Observer” pattern in Java

 

An external reference cannot have attributes or operations, as it is defined outside of and does not depend on the pattern. However, it can be used to define links (associations, generalization, implementations) or as an attribute type or operation parameter.

 

A pattern containing an external reference cannot be applied if the referenced elements do not exist in the application project. In the case of an external reference which is not situated within the model (its access path is modified in the Objecteering project), then the window shown in Figure 153 automatically opens, thereby allowing the user to select the referenced element from the model.

 

Figure 153. The “Locate external reference” window