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.

Locating a pattern to apply

Learn how to find the types of documentation that is available in a pattern.
  1. In the Pattern Explorer view, expand the Sample Patterns group. Locate the Interface pattern.
  2. Click the Interface pattern. A description of the pattern displays in the Pattern Explorer view's Short Description pane.
  3. Click the Overview tab. A simple model of the relationship of the pattern elements reveals the potential use of the pattern.
  4. Expand the Interface pattern to view the pattern's parameters. The pattern owns two parameters named Interface and Implementation.
  5. Click each parameter and read the short description for each. The description explains the function that the parameter performs in the pattern.
  6. Right-click the Interface pattern and click Show Pattern Documentation. The online Help opens with additional information about this pattern.
You can use the pattern documentation to understand the purpose of the pattern. Documentation varies according to what a pattern author chooses to provide.

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 that dragging an element onto a pattern instance will replace a 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.

Terms of use | Feedback
(C) Copyright IBM Corporation 2004, 2005. All Rights Reserved.