Combined fragments in sequence diagrams

In sequence diagrams, combined fragments are logical groupings, represented by a rectangle, which contain the conditional structures that affect the flow of messages. A combined fragment contains interaction operands and is defined by the interaction operator.

The type of combined fragment is determined by the interaction operator. You can use combined fragments to describe several control and logic structures in a compact and concise manner. The interaction operator identifies the type of logic or conditional statement that defines the behavior of the combined fragment.

As the following figure illustrates, a combined fragment is displayed as a frame that covers lifelines and that contains interaction operands. A combined fragment separates the contained interaction operands with a dashed horizontal line between each operand.

An interaction frame shows the interaction operator, operand, and guard conditions that the combined fragment contains.

Interaction operators

An interaction operator defines the semantics of a combined fragment and determines how to use the interaction operands in the combined fragment. The operator defines the type of logical conditions to apply to the operands. For example, a combined fragment with the alternative (alt) interaction operator acts like an if-then-else statement. In the previous figure, a loop and alternative (alt) interaction operator define the two combined fragments.

Interaction operands

In sequence diagrams, an interaction operand is a container that groups the interaction fragments and messages that run if the guard condition is met. If there is no guard condition, the block always runs.

Each interaction operand is a fragment of an interaction and covers the lifelines in the combined fragment. An interaction operand contains a guard condition, which contains an interaction constraint. The interaction operand runs only if the guard condition tests true.

Depending on the type of interaction operator, you can have one or more interaction operands in a combined fragment. Each operand must have a guard condition.

When you create an interaction operand, it appears in an expanded state. You can collapse the interaction operand to hide the operand and its associated messages and interaction fragments and to minimize the size of the combined fragment in the interaction frame.

In the previous figure, the alternative (alt) combined fragment contains two interaction operands; one with a guard condition x>5 and the other interaction operand with the guard condition x<=5. If x=6, the x<=5 guard condition and corresponding operand and messages run. The x>5 guard condition and corresponding operand and contained messages do not run.

Guard conditions

In sequence diagrams, a guard condition contains an interaction constraint, which is a Boolean conditional expression or, in the case of a loop, an expression that designates the minimum and maximum number of times the loop runs and, optionally, the incremental value.

A guard condition is a semantic condition or restriction that is set in square brackets in an interaction operand in a combined fragment. When you create a combined fragment, a guard condition is created automatically. You can also manually create a guard condition in an interaction operand that does not have an existing guard condition.

A guard condition appears at the start of the interaction and contains all the information that is required to make the decision about whether to run the interaction operand. If the guard condition tests true, the interaction fragment runs.

As the following figure illustrates, an interaction operand is displayed as a rectangle in a combined fragment. The rectangle can contain messages that run if the guard condition is true. The code on the right is what pseudocode would like for the alternative (alt) combined fragment.
An interaction frame shows two lifelines with two combined fragments that cross the lifelines. The first loop combined fragment has one interaction operand and a guard condition. The second alt combined fragment has two interaction operands, each with a guard condition.
// This section is a combined fragment


//if else represents the interaction operator 
//if-else is the Alternative(alt) combined fragment
if ( value is greater than 5)
// the condition in the () is the guard condition
// The code in the {} is the interaction operand
// It runs if the guard condition is true
	{ A send a message to B;
	B sends a return message to A;
	}
else if(x is less than or equal to 5)		 
{
	B sends a message to A;
}
Related tasks
Creating combined fragments in sequence diagrams
Managing interaction operands in sequence diagrams
Adding guard conditions to sequence diagrams
Managing combined fragments in sequence diagrams
Related reference
Interaction operators in sequence diagrams

Feedback