Exercise 6: Binding existing elements as arguments

This exercise explores two different ways to specify existing UML model elements as pattern template arguments.

Instead of creating a new UML element, you can select existing elements by typing the name of an existing element in the pattern instance on the diagram view. Or you can drag an existing element from the Model Explorer view or the diagram view onto the pattern instance.

If you would like to view this exercise before you perform the steps, click:

Show me button Show Me

Before you begin, you must complete Exercise 5: Binding new elements to pattern instances.

Specifying the name of an existing element as an argument

You added a new argument value in the last exercise that was similar to the following steps. Now you will type the name of an existing element instead of creating a new element.
  1. On the freeform or class diagram, hold the cursor over the Implementation parameter in the pattern instance. The action bar is displayed and a Class icon and a Text icon are available.
  2. Click the Text icon on in the action bar to type the name of an existing UML class element. A rectangular box appears next to the right-side of the template parameter.
  3. In the box, type AppFunction1 to specify the class from the sample model.
  4. Click outside the instance or press Enter to complete the name. A binding symbol replaces the blank box next to the template parameter followed by the name of the element.
  5. Observe the changes to the template binding in the Model Explorer view. The binding structure now shows the AppFunction1 class bound to the Implementation template parameter.
The most important result is the two operations from the DoWork interface are now copied to the AppFunction1 class.

Dragging an existing element as an argument

This is the easiest method to add an argument to the pattern instance.
  1. On the freeform or class diagram, drag and drop the DoWork interface onto the left side of the Interface row in the pattern instance.
    Note: Dragging an element onto a pattern instance will replace a previously bound element if the bound element was selected.
  2. In the Model Explorer view, observe the addition of the doNothing and doSomething operations to the AppFunction1 class resulting from the pattern binding.
  3. In the Model Explorer view, expand the instance's template binding structure to see the addition of the new interface element. The Interface template parameter is bound to a third interface element named DoWork.

You are ready to reapply the pattern to see the pattern to observe its effects the model elements. Go on to Exercise 7: Reapplying the pattern.

Feedback
(C) Copyright IBM Corporation 2004, 2005. All Rights Reserved.