Exercise 5: Binding new elements to pattern instances

This exercise explores different methods of adding or binding arguments to the pattern instance.

When binding occurs, the pattern instance's template parameters are replaced by the selected or newly created elements specified by the pattern applier.

Whether you select existing elements or create new elements as arguments depends on what you want the pattern to do. In this tutorial, different methods are explored so that you can learn about them.

On the freeform or class diagram, you can use the action bar to add elements. To see the action bar, gently move the cursor over the blank diagram view surface or any elements. You can hold the cursor over the template parameters in the pattern instance to display the action bar with only the elements that are applicable to the UML type of the template parameter.

If the action bar disappears in a few seconds, tap the spacebar to re-display it.

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 4: Creating an instance of the pattern.

Creating a new element as an argument

This is a simple method to add an argument value with a default name to the pattern instance.
  1. On the freeform or class diagram, hold the cursor over the pattern instance's Interface parameter. The action bar is displayed.
  2. Click the interface icon on the action bar to create and bind an interface element to the template parameter. A binding symbol replaces the blank box next to the template parameter followed by the UML type of the element (interface), indicating that the new element is bound to the pattern instance.
  3. In the Model Explorer view, note the addition of the new interface element in the UML model. The pattern instance's template binding structure also shows the Interface template parameter bound to an Interface element.

Creating a custom-named element as an argument

This method of adding an argument is the same as above except you have the option of naming the element before it is bound.
  1. On the freeform or class diagram, hover the cursor over the Interface parameter in the pattern instance. On the action bar, the icons are available for selection indicating that the multiplicity for the template parameter allows the binding of another element.
  2. Click the Text icon to the right of the interface icon on the action bar. A rectangular box appears next to the right-side of the template parameter.
  3. In the box, type IMyInterface to name the new element and click outside of the instance or press Enter to complete the name. A binding symbol replaces the blank box next to the template parameter followed by the UML type of the element (interface).
  4. Observe the changes to the template binding structure in the Model Explorer view. The binding structure now shows the Interface template parameter bound to an additional UML interface element named IMyInterface.

You are ready to learn two more methods of adding arguments to a pattern instance so go to Exercise 6: Binding existing elements as arguments.

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