Interaction diagrams are about deciding and modeling how your system will achieve what you described in your use case models. Interaction diagrams enable you to visualize, specify, construct, and document the dynamics of how each object in your system interacts (exchanges messages) in order to perform a particular task. The context of a task equates to a single use case scenario. UML provides two types of interaction diagrams that can be used to model the interactions between objects within the context of a use case scenario: Sequence and Collaboration diagrams. The Sequence and Collaboration diagrams represent two dynamic perspectives to view exactly the same information as they both model the messages that are passed between objects. Also, Sequence and Collaboration diagrams are isomorphic , implying that you can easily derive one from the other. In fact, most modeling tools, such as the Together ControlCenter, will automatically generate one diagram from the other. Distinctions between the Sequence and Collaboration diagrams exist in how they portray the same information, as follows :
Both Interaction diagrams provide a visual representation of the objects in a system's design and the order they send messages to each other. In UML terminology, sending a message refers to calling one of the operations ( methods ) of an object. Hence, the Class diagrams in conjunction with the Interaction diagrams can provide an initial platform to begin coding a solution. Because Sequence and Collaboration diagrams are isomorphic, you can learn how to model one of them and catalyze your comprehension of the other through the use of a professional modeling tool, which can perform the conversion between the two model types. The following section will describe the most common features of a Sequence diagram. The Features of a Sequence DiagramAs illustrated in Figure 3.23, a Sequence diagram has two dimensions:
Note The axes can be interchanged, so that time proceeds horizontally to the right and different objects are shown as horizontal lines. The control of flow by time in a use case scenario is represented in a Sequence diagram through the following:
Figure 3.24 illustrates how you can represent objects, object lifelines, focus of control, links, and messages in the context of a Sequence diagram. Figure 3.24. The representation of objects, object lifelines, focus of control, links, and messages in the context of a Sequence diagram.
In addition to the basic flow of control, as illustrated in Figure 3.24, you can also represent the following control flows in a Sequence diagram:
The Sequence diagram in Figure 3.28 represents the focus of control, conditional selection, recursion, creation, and destruction aspects of a Sequence diagram. Figure 3.28. The representation of a focus of control, conditional selection, recursion, creation, and destruction aspects of a Sequence diagram.
The Collaboration diagram for the Sequence diagram represented by Figure 3.28 is illustrated in Figure 3.29, which can easily be generated using a professional modeling tool. Figure 3.29. The Collaboration diagram representing the Sequence diagram in Figure 3.28.
Note A Sequence and Collaboration diagram based on a use case scenario is described in the section "UML By Example ”The Book Store," which appears at the end of this chapter. Tip Because object-oriented software development is an iterative process, it is often very helpful to write some prototype code to help solidify the design. This becomes evident while developing Sequence diagrams, where you may realize that you need a message that is not yet an operation in the Class diagram. You must therefore update the Class diagram to include the new operation. To maintain traceability, any modifications to your analysis or design must be put back into all affected diagrams. This is not as bad as it sounds if you are using a professional UML modeling tool, such as the Together ControlCenter. |