Home

 

Creating combined fragments

UML 2.0 introduced the concept of combined fragments to support conditional and looping constructs such as if-then-else statements or to enable parts of an interaction to be reused.

Combined fragments are frames that encompass portions of a sequence diagram or provide reference to other diagrams.

A combined fragment is represented by a rectangle that comprises one or more lifelines. Its behavior is defined by an interaction operator that is drawn as a notched descriptor box in the upper left corner of the combined fragment. For example, the alternative interaction operator (alt) acts like an if-then-else statement and is shown in Figure | -39.

Figure 7-39 Sequence diagram with an alternative combined fragment

UML 2.0 provides many other interaction operators for use with combined fragments. Depending on its type, a combined fragment can have one or more interaction operands. Each interaction operand represents a fragment of the interaction with an optional guard condition. The interaction operand is executed only if the guard condition is true at runtime. The absence of a guard condition means that the combined fragment is always executed. The guard condition is displayed as plain text enclosed within two square brackets. A combined fragment separates the contained interaction operands with a dashed horizontal line between each operand within the frame of the combined fragment. When the combined fragment contains only one operand, the dashed line is unnecessary.

Figure | -39 shows a fragment being used in a withdraw cash interaction. The combined fragment is used to model an alternative flow in the interaction. Because of the guard condition [amount<balance], if the account balance is greater than the amount of money the customer wants to withdraw, the first interaction operand is executed. This means the interaction debits the account. Otherwise the [else] guard forces the second interaction operand to be executed. An insufficient fund fee is added to the account and the transaction is canceled.

To create a combined fragment, first select the desired fragment in the palette. Click the solid triangle right next to the Combined Fragment category and select the desired fragment from the available fragments. Then click the left mouse button within an empty place in the diagram and drag the combined fragment across the lifelines that you want to include in it. When you release the mouse button, the Add Covered Lifelines dialog opens and this allows you to select the individual lifelines to be covered by the combined fragment. Each lifeline is represented by a check box, and each of them is selected by default. When you click OK a new combined fragment along with one or two interaction operands is created.

Figure | -40 shows a newly created alternative combined fragment with two empty interaction operands. To specify a guard condition for an interaction operand, select the corresponding brackets and enter the text. You can create messages between the individual lifelines covered by the combined fragment in the same way as described previously. Note how the sequence numbers of the individual messages change within an interaction operand. You can also nest other combined fragments within an existing combined fragment.

Figure 7-40 Empty combined fragment with two interaction operands

After a combined fragment has been created, it is not possible to change its type, or more precisely, its interaction operator. But if you right-click a combined fragment, the context menu allows you to add new interaction operands if you select Add Interaction Operand or to add and remove lifelines from the selected element if you select Covered Lifelines.

When you create an interaction operand, it appears in an expanded state. By clicking the small triangle at the top of the interaction operand you can collapse it to hide the entire operand and its associated messages. From the context menu of an operand there are several options available to remove or reposition the selected operand. Further, you are able to add a guard condition to the operand or to add a new interaction operand if the enclosing combined fragment allows multiple operands

ibm.com/redbooks