Terms and Concepts
An interaction diagram shows an interaction, consisting of a set of objects and their relationships, including the messages that may be dispatched among them. A sequence diagram is an interaction diagram that emphasizes the time ordering of messages. Graphically, a sequence diagram is a table that shows objects arranged along the X axis and messages, ordered in increasing time, along the Y axis. A communication diagram is an interaction diagram that emphasizes the structural organization of the objects that send and receive messages. Graphically, a communication diagram is a collection of vertices and arcs.
Common Properties
An interaction diagram is just a special kind of diagram and shares the same common properties as do all other diagramsa name and graphical contents that are a projection into a model. What distinguishes an interaction diagram from all other kinds of diagrams is its particular content.
The general properties of diagrams are discussed in Chapter 7 . |
Contents
Objects are discussed in Chapter 13; links are discussed in Chapters 14 and 16; messages and interactions are discussed in Chapter 16; internal structure is discussed in Chapter 15; collaborations are discussed in Chapter 28 . |
- Roles or objects
- Communications or links
- Messages
NoteAn interaction diagram is basically a projection of the elements found in an interaction. The semantics of an interaction's context, objects and roles, links and connectors, messages, and sequencing apply to interaction diagrams.Like all other diagrams, interaction diagrams may contain notes and constraints.
Sequence Diagrams
A sequence diagram emphasizes the time ordering of messages. As Figure 19-2 shows, you form a sequence diagram by first placing the objects or roles that participate in the interaction at the top of your diagram, across the horizontal axis. Typically, you place the object or role that initiates the interaction at the left, and increasingly more subordinate objects or roles to the right. Next, you arrange the messages that these objects send and receive along the vertical axis in order of increasing time from top to bottom. This gives the reader a clear visual cue to the flow of control over time.
Figure 19-2. Sequence Diagram

Structured Control in Sequence Diagrams
A sequence of messages is fine for showing a single, linear sequence, but often we need to show conditionals and loops. Sometimes we want to show concurrent execution of multiple sequences. This kind of high-level control can be shown using structured control operators in sequence diagrams.A control operator is shown as a rectangular region within the sequence diagram. It has a taga text label inside a small pentagon in the upper left cornerto tell what kind of a control operator it is. The operator applies to the lifelines that cross it. This is considered the body of the operator. If a lifeline does not apply to the operator, it may be interrupted at the top of the control operator and resumed at the bottom. The following kinds of control are the most common:
Optional execution
The tag is opt. The body of the control operator is executed if a guard condition is true when the operator is entered. The guard condition is a Boolean expression that may appear in square brackets at the top of any one lifeline within the body and may reference attributes of that object.
Conditional execution
The tag is alt. The body of the control operator is divided into multiple subregions by horizontal dashed lines. Each subregion represents one branch of a conditional. Each subregion has a guard condition. If the guard condition for a subregion is true, the subregion is executed. However, at most one subregion may be executed; if more than one guard condition is true, the choice of subregion is nondeterministic and could vary from execution to execution. If no guard condition is true, then control continues past the control operator. One subregion may have a the special guard condition [else]; this subregion is executed if none of the other guard conditions are true.
Parallel execution
The tag is par. The body of the control operator is divided into multiple subregions by horizontal dashed lines. Each subregion represents a parallel (concurrent) computation. In most cases, each subregion involves different lifelines. When the control operator is entered, all of the subregions execute concurrently. The execution of the messages in each subregion is sequential, but the relative order of messages in parallel subregions is completely arbitrary. This construct should not be used if the different computations interact. There are very many real-world situations that decompose into independent, parallel activities, however, so this is a very useful operator.
Loop (iterative) execution
The tag is loop. A guard condition appears at the top of one lifeline within the body. The body of the loop is executed repeatedly as long as the guard condition is true before each iteration. When the guard condition is false at the top of the body, control passes out of the control operator.There are many other kinds of operators, but these are the most useful.To provide a clear indication of the boundary, a sequence diagram may be enclosed in a rectangle, with a tag in the upper left corner. The tag is sd, which may be followed by the name of the diagram.Figure 19-3 shows a simplified example that illustrates some control operators. The user initiates the sequence. The first operator is a loop operator. The numbers in parentheses (1,3) indicate the minimum and maximum number of times the loop body must be executed. Since the minimum is one, the body is always executed at least once before the condition is tested. In the loop, the user enters the password and the system verifies it. The loop continues as long as the password is incorrect. However, after three tries, the loop terminates in any case.
Figure 19-3. Structured Control Operators

Nested Activity Diagrams
Activity diagrams that are too large can be difficult to understand. Structured sections of an activity can be organized into a subordinate activity, especially if the subordinate activity is used more than once within the main activity. The main activity and the subordinate activities are shown on separate diagrams. Within the main activity diagram, a use of a subordinate activity is shown by a rectangle with the tag ref in its upper left corner; the name of the subordinate behavior is shown in the box. The subordinate behavior is not restricted to an activity diagram; it could also be a state machine, sequence diagram, or other behavioral specification. Figure 19-4 shows the diagram from Figure 19-3 rearranged by moving two sections into separate activity diagrams and referencing them from the main diagram.
Figure 19-4. Nested activity diagram

Communication Diagrams
A communication diagram emphasizes the organization of the objects that participate in an interaction. As Figure 19-5 shows, you form a communication diagram by first placing the objects that participate in the interaction as the vertices in a graph. Next, you render the links that connect these objects as the arcs of this graph. The links may have rolenames to identify them. Finally, you adorn these links with the messages that objects send and receive. This gives the reader a clear visual cue to the flow of control in the context of the structural organization of objects that collaborate.
Figure 19-5. Communication Diagram

You can use an advanced form of sequence numbers to distinguish concurrent flows of control, as discussed in Chapter 23; path stereotypes are discussed in Chapter 18; complex branching and iteration can be more easily specified in activity diagrams, as discussed in Chapter 20 . |
Semantic Equivalence
Because they both derive from the same information in the UML's metamodel, sequence diagrams and communication diagrams are semantically equivalent. As a result, you can take a diagram in one form and convert it to the other without any loss of information, as you can see in the previous two figures, which are semantically equivalent. However, this does not mean that both diagrams will explicitly visualize the same information. For example, in the previous two figures, the communication diagram shows how the objects are linked (note the {local} and {global} annotations); the corresponding sequence diagram does not. Similarly, the sequence diagram shows message return (note the return value committed), but the corresponding communication diagram does not. In both cases, the two diagrams share the same underlying model, but each may render some things the other does not. However, a model entered in one format may lack some of the information shown on the other format, so although the underlying model can include both kinds of information, the two kinds of diagrams may lead to different models.
The five views of an architecture are discussed in Chapter 2; instances are discussed in Chapter 13; classes are discussed in Chapters 4 and 9; active classes are discussed in Chapter 23; interfaces are discussed in Chapter 11; components are discussed in Chapter 15; nodes are discussed in Chapter 27; systems and subsystems are discussed in Chapter 32; operations are discussed in Chapters 4 and 9; use cases are discussed in Chapter 17; collaborations are discussed in Chapter 28 . |
Common Uses
You use interaction diagrams to model the dynamic aspects of a system. These dynamic aspects may involve the interaction of any kind of instance in any view of a system's architecture, including instances of classes (including active classes), interfaces, components, and nodes.When you use an interaction diagram to model some dynamic aspect of a system, you do so in the context of the system as a whole, a subsystem, an operation, or a class. You can also attach interaction diagrams to use cases (to model a scenario) and to collaborations (to model the dynamic aspects of a society of objects).When you model the dynamic aspects of a system, you typically use interaction diagrams in two ways.Here you'll use sequence diagrams. Modeling a flow of control by time ordering emphasizes the passing of messages as they unfold over time, which is a particularly useful way to visualize dynamic behavior in the context of a use case scenario. Sequence diagrams do a better job of visualizing simple iteration and branching than do communication diagrams.Here you'll use communication diagrams. Modeling a flow of control by organization emphasizes the structural relationships among the instances in the interaction, along which messages may be passed.