Common Modeling Techniques
Modeling Flows of Control by Time Ordering
Consider the objects that live in the context of a system, subsystem, operation or class. Consider also the objects and roles that participate in a use case or collaboration. To model a flow of control that winds through these objects and roles, you use an interaction diagram; to emphasize the passing of messages as they unfold over time, you use a sequence diagram, a kind of interaction diagram.
Systems and subsystems are discussed in Chapter 32; operations and classes are discussed in Chapters 4 and 9; use cases are discussed in Chapter 17; collaborations are discussed in Chapter 28 . |
- Set the context for the interaction, whether it is a system, subsystem, operation, or class, or one scenario of a use case or collaboration.
- Set the stage for the interaction by identifying which objects play a role in the interaction. Lay them out on the sequence diagram from left to right, placing the more important objects to the left and their neighboring objects to the right.
- Set the lifeline for each object. In most cases, objects will persist through the entire interaction. For those objects that are created and destroyed during the interaction, set their lifelines, as appropriate, and explicitly indicate their birth and death with appropriately stereotyped messages.
- Starting with the message that initiates this interaction, lay out each subsequent message from top to bottom between the lifelines, showing each message's properties (such as its parameters), as necessary to explain the semantics of the interaction.
- If you need to visualize the nesting of messages or the points in time when actual computation is taking place, adorn each object's lifeline with its focus of control.
- If you need to specify time or space constraints, adorn each message with a timing mark and attach suitable time or space constraints.
- If you need to specify this flow of control more formally, attach pre- and postconditions to each message.
Timing marks are discussed in Chapter 24; pre- and postconditions are discussed in Chapter 4; packages are discussed in Chapter 12 . |
Figure 19-6. Modeling Flows of Control by Time Ordering

Signals are discussed in Chapter 21; timing marks are discussed in Chapter 24; constraints are discussed in Chapter 6; responsibilities are discussed in Chapter 4; notes are discussed in Chapter 6 |
Modeling Flows of Control by Organization
Consider the objects that live in the context of a system, subsystem, operation, or class. Consider also the objects and roles that participate in a use case or collaboration. To model a flow of control that winds through these objects and roles, you use an interaction diagram; to show the passing of messages in the context of that structure, you use a communication diagram, a kind of interaction diagram.
Systems and subsystems are discussed in Chapter 32; operations and classes are discussed in Chapters 4 and 9; use cases are discussed in Chapter 17; collaborations are discussed in Chapter 28 . |
- Set the context for the interaction, whether it is a system, subsystem, operation, or class, or one scenario of a use case or collaboration.
- Set the stage for the interaction by identifying which objects play a role in the interaction. Lay them out on the communication diagram as vertices in a graph, placing the more important objects in the center of the diagram and their neighboring objects to the outside.
- Specify the links among these objects, along which messages may pass.
- Lay out the association links first; these are the most important ones, because they represent structural connections.
- Lay out other links next, and adorn them with suitable path annotations (such as global and local) to explicitly specify how these objects are related to one another.
Dependency relationships are discussed in Chapters 5 and 10; path constraints are discussed in Chapter 16 - Starting with the message that initiates this interaction, attach each subsequent message to the appropriate link, setting its sequence number, as appropriate. Show nesting by using Dewey decimal numbering.
- If you need to specify time or space constraints, adorn each message with a timing mark and attach suitable time or space constraints.
- If you need to specify this flow of control more formally, attach pre- and postconditions to each message.
Timing marks are discussed in Chapter 24; pre- and postconditions are discussed in Chapter 4; packages are discussed in Chapter 12 . |
Figure 19-7. Modeling Flows of Control by Organization

Forward and Reverse Engineering
Forward engineering (the creation of code from a model) is possible for both sequence and communication diagrams, especially if the context of the diagram is an operation. For example, using the previous communication diagram, a reasonably clever forward engineering tool could generate the following Java code for the operation register, attached to the Student class.
"Reasonably clever" means the tool would have to realize that getSchedule returns a CourseCollection object, which it could determine by looking at the operation's signature. By walking across the contents of this object using a standard iteration idiom (which the tool could know about implicitly), the code could then generalize to any number of course offerings.Reverse engineering (the creation of a model from code) is also possible for both sequence and communication diagrams, especially if the context of the code is the body of an operation. Segments of the previous diagram could have been produced by a tool from a prototypical execution of the register operation.NoteForward engineering is straightforward; reverse engineering is hard. It's easy to get too much information from simple reverse engineering, so the hard part is being clever about what details to keep.However, more interesting than the reverse engineering of a model from code is the animation of a model against the execution of a deployed system. For example, given the previous diagram, a tool could animate the messages in the diagram as they were dispatched in a running system. Even better, with this tool under the control of a debugger, you could control the speed of execution, possibly setting breakpoints to stop the action at interesting points to examine the attribute values of individual objects.
public void register() {
CourseCollection courses = getSchedule();
for (int i = 0; i < courses.size(); i++)
courses.item(i).add(this);
this.registered = true;
}