Rational Software Corp.

TOC PREV NEXT INDEX



Interaction Diagrams and Specifications


Contents

This chapter is organized as follows:


Interaction Diagram Overview

An interaction is an important sequence of interactions between objects. Rational Rose provides two alternate views or representations of each interaction--a collaboration and sequence diagram. These are collectively referred to as interaction diagrams. The main difference between sequence and collaboration diagrams is that sequence diagrams show time-based object interaction while collaboration diagrams show how objects associate with each other.

You can specify and modify an interaction with either kind of diagram, or with both. Rational Rose automatically reflects all changes made either to a sequence or collaboration diagram in the corresponding collaboration or sequence diagram, if one has been created.

Creating and Displaying an Interaction Diagram

To create or display a collaboration or sequence diagram:

1 Click Browse > Interaction Diagram.

    The Select Interaction Diagram dialog box is displayed.

2 Select a package to "own" the diagram.

3 On the right side of the dialog box, click the diagram name, and then click OK.

4 From the New Interaction Diagram dialog box, enter the diagram title and click the diagram type. Your choices are Sequence or Collaboration. Each diagram type is described in detail later in this chapter.


Collaboration Diagrams

A collaboration diagram is an interaction diagram which shows the sequence of messages that implement an operation or a transaction. These diagrams show objects, their links, and their messages. They can also contain simple class instances and class utility instances. Each collaboration diagram provides a view of the interactions or structural relationships that occur between objects and object-like entities in the current model.

You can create one or more collaboration diagrams to depict interactions for each logical package in your model. Such collaboration diagrams are themselves contained by the logical package enclosing the objects they depict.

During analysis, collaboration diagrams can indicate the semantics of the primary and secondary interactions.

During design, collaboration diagrams can show the semantics of mechanisms in the logical design of the system.

Use collaboration diagrams as the primary vehicle to describe interactions that express your decisions about the behavior of the system. They can also be used to trace the execution of a scenario by capturing the sequential and parallel interaction of a cooperating set of objects.

Collaboration diagrams may also depict interactions that illustrate system behavior.

Figure 69 Collaboration Diagram Example


Sequence Diagrams

A sequence diagram is a graphical view of a scenario that shows object interaction in a time-based sequence--what happens first, what happens next. Sequence diagrams establish the roles of objects and help provide essential information to determine class responsibilities and interfaces. Sequence diagrams are normally associated with use cases.

This type of diagram is best used during early analysis phases in design because they are simple and easy to comprehend. A sequence diagram has two dimensions: typically, vertical placement represents time and horizontal placement represents different objects.

Sequence diagrams are closely related to collaboration diagrams and each are alternate representations of an interaction.

A sequence diagram traces the execution of a scenario in time. Figure 70 shows a sequence diagram.

Figure 70 Sequence Diagram Example


Toolboxes

Each diagram type has its own unique toolbox. The collaboration and sequence diagram toolboxes are illustrated in this section.

Collaboration Diagram Toolbox

The graphic below shows all the tools that can be placed on the collaboration diagram toolbox. Refer to Customizing the Toolbox for information on adding or deleting tools on a diagram toolbox.

The application window displays the following toolbox when the current window contains a collaboration diagram and you have selected View > As Unified.

Note: Some icons will be different if you have selected View > As Booch or View > As OMT.

Figure 71 Collaboration Diagram Toolbox

Sequence Diagram Toolbox

The graphic below shows all the tools that can be placed on the sequence diagram toolbox. Refer to Customizing the Toolbox for information on adding or deleting tools on a diagram toolbox.

The application window displays the following toolbox when the current window contains a sequence diagram and you have selected View > As Unified.

Note: Some icons will be different if you have selected View > As Booch or View > As OMT.

Figure 72 Sequence Diagram Toolbox

Note: The object and message icons are also found in the collaboration toolbox.

Common Collaboration and Sequence Diagram Icons

There are a number of common tools that are used on both collaboration and sequence diagrams. Although they differ slightly, they illustrate common concepts or elements. Tools unique to a specific diagram type are discussed after this section.

Object

One of the primary elements of a collaboration or sequence diagram is an object. An object has state, behavior, and identity. The structure and behavior of similar objects are defined in their common class. Each object in a diagram indicates some instance of a class. An object that is not named is referred to as a class instance.

The object icon is similar to a class icon except that the name is underlined.

If you use the same name for several object icons appearing in the same collaboration diagram, they are assumed to represent the same object; otherwise, each object icon represents a distinct object. Object icons appearing in different diagrams denote different objects, even if their names are identical. Objects can be named three different ways: object name, object name and class, or just by the class name itself.

Multiple Objects

If you have multiple objects that are instances of the same class, you can modify the object icon by selecting the Multiple Instances check box in the Object Specification. When you select this check box, the icon is changed from one object to three staggered objects.

To create an icon representing multiple objects:

1 Create an object.

2 Double-click its icon to display its specification.

3 Select the Multiple Instances check box.

4 Click OK.

    Rational Rose displays the Multiple Object icon.

Figure 73 Multiple Object Diagram

Messages

A message icon represents the communication between objects, indicating that an action will follow.

Each message icon represents a message passed between two objects, and indicates the direction a message is going. A message icon in a collaboration diagram can represent multiple messages. A message icon in a sequence diagram represents exactly one message.

A message is the communication carried between two objects that triggers an event. A message carries information from the source focus of control to the destination focus of control.

A message is represented on collaboration diagrams and sequence diagrams by a message icon which visually indicates its synchronization. The synchronization of a message can be modified through the message specification.

If all messages represented by a message icon do not have the same synchronization, the simple message icon is displayed. You can change the synchronization of the message by editing the message specification.

The sequence diagram toolbox contains two message tools. The message icon tool appears as a horizontal arrow. The message to self icon appears as a message that returns to itself.

The collaboration diagram toolbox contains two message tools. The forward message tool, bearing an arrow pointing up and to the right, places a message icon from client to supplier. The reverse message tool, bearing an arrow pointing down and to the left, places a message icon from supplier to client. The default synchronization for a message is simple.

Scripts may be attached to messages to enhance the messages.

If a message is deleted, the link on the collaboration diagram remains intact.

To create a client-to-supplier message and assign it to a link between two objects (collaboration diagram only):

1 Click the Message icon.

2 Click an icon representing the link.

Rational Rose creates an unnamed, empty message assigned to the designated link. The source of this message is the client object, and the destination of this message is the supplier object.

To create a supplier-to-client message, use the Reverse Message Creation tool in the above procedure. The source of the resulting message is the supplier-object, and the destination of this message is the client-object.

To name an unnamed message:

1 Click the icon representing the message.

2 Type the name.

3 Click outside the named icon.

Rational Rose will name the message as specified and assign it a sequence number based on creation order, starting with 1.

To change message names in interaction diagrams:

1 Click the name to display a flashing vertical bar that designates the insertion point.

2 Enter additional text.

3 Click outside the named icon.

Alternatively, you can double-click an icon representing the message to display the message specification. Then, modify the Name field and click OK.

Message Numbering

To enable or disable the display of message numbers click Tools > Options. Click the Diagram tab and click Collaboration Numbering (for collaboration diagrams) or Sequence Numbering (for sequence diagrams).

To change messages numbering in interaction diagrams:

1 Create or display the interaction's sequence diagram, click Browse > Create Sequence Diagram or Browse > Go to Sequence Diagram.

2 Reorder the messages by dragging the message icons into the preferred order.

3 Redisplay the interaction diagram by clicking Browse > Go to Collaboration Diagram or Browse > Go to Sequence Diagram.

Assigning an Operation to a Message

Rational Rose allows you to assign an operation to a message by presenting a list of all operations accepted by the destination object. The list of valid operations is defined by the specification of the object's parent class and the specifications of the parent class' superclasses, as specified by its inheritance hierarchy. The Class field of the destination object's specification must be set to identify the destination object's parent class before operations can be assigned to a message to that destination object.

Assigning an operation to a message changes the name of the message to the name of the operation.

To assign an operation to a message:

1 Right-click the message icon.

2 Click an operation from the pop-up list, or click <new operation> to add and specify a new operation to the destination object's Class Specification.

If you click <new operation>, you must repeat this procedure after specifying the new operation to assign the newly-created operation to the message.

You can associate multiple messages with a message icon. Each new message is represented by an independent name and sequence number. If a message icon represents multiple messages, you must select a specific message by clicking its name.

You can also create multiple messages associated with the same message icon using the Link Specification. This method is described in Link Specification.

To change a message's assigned operation, display its specification by double-clicking its message icon. If the message icon represents multiple messages, double-click the name of the message whose operation you select to change. Select the desired operation from the specification's Referenced Operation field, or directly enter an operation name in the Name field.

Collaboration-Specific Toolbox Icons

Links

Objects interact through their links to other objects. A link is an instance of an association, analogous to an object being an instance of a class.

A link should exist between two objects, including class utilities, only if there is a relationship between their corresponding classes. The existence of a relationship between two classes symbolizes a path of communication between instances of the classes: one object may send messages to another.

Links can support multiple messages in either direction. If a message is deleted, the link remains intact.

The link is depicted as a straight line between objects or objects and class instances in a collaboration diagram. If an object links to itself, use the loop version of the icon.

To create a link between two objects:

1 Click the Link tool.

2 Drag the pointer between the two object icons.

Rational Rose will create and display an unnamed link.

To create a reflexive link (a link between an object and itself):

1 Click the Link to Self tool.

2 Click an icon representing the object.

Rational Rose will create and display an unnamed reflexive link.


Sequence Numbering

Sequence numbering allows you to clearly see how messages interact and relate to one another. Numbering messages can be done two ways on sequence diagrams: top level numbering (a 1, 2, 3 pattern) or hierarchical numbering (a 1.1, 1.1.2, 1.1.3 pattern). Only top level numbering is available on collaboration diagrams. However, if you create a collaboration diagram from a sequence diagram with hierarchal numbering, the hierarchal numbering is retained.

Top-Level Numbering

Top-level numbering gives each message or message to self a single number. There are no number subsets. Top-level numbering is useful in small sequence diagrams with few objects and messages.

Hierarchical Numbering

Hierarchical numbering bases all messages on a dependent message. For example, you could have messages numbered 1., 1.1, 1.2, 1.2.1, where message number 1 is an independent message. All other message numbers numbered 1.x and beyond are dependent on message 1. If you remove independent message 1 from the diagram, all dependent messages will be removed.

To display hierarchical numbering:

1 Click Tools > Options.

2 Click the Diagram tab.

3 Select the Sequence Numbering check box.

4 Select the Hierarchical Messages check box.

Scripts

Scripts are used to enhance messages on sequence diagrams; they are text fields that attach to messages.

To create and attach a script:

1 Click the message icon and drag it between two objects.

2 Create text by either:

3 Select one or more labels. Press the ctrl or shift key to enable multiple selections.

4 Select one message.

5 Click Edit > Attach Script to attach the script to the message.

To move a script:

1 Select the message and drag it.

    The script moves next to the message.

2 Select only the script and drag it.

    The script moves independently of the message.

To detach a script:

1 Select either a script or a message.

2 Click Edit > Detach Script.

To delete messages, scripts, or objects:

To undo:


Focus of Control

Focus of Control (FOC) is an advanced notational technique that enhances sequence diagrams. This technique shows the period of time during which an object is performing an action, either directly or through an underlying procedure.

FOC is portrayed through narrow rectangles that adorn lifelines (the vertical lines descending from each object). The length of an FOC indicates the amount of time it takes for a message to be performed. When you move a message vertically, each dependent message will move vertically as well. Also, you can move an FOC vertically off the source FOC to make it detached and independent.

Figure 74 illustrates a sequence diagram with FOC notation and scripts.

Figure 74 Focus of Control Diagram Example

Displaying Focus of Control

To enable the Focus of Control notation on a sequence diagram:

1 Click Tools > Options.

2 Click the Diagram tab.

3 Select the Focus of control check box.

Coloring Focus of Control

To help distinguish a particular FOC from other items in a sequence diagram, you can fill an FOC with a color.

To color an FOC:

1 Select the message icon that enters the FOC you want to color.

2 Click Format > Fill Color.

3 Click the color you want to make the selected FOC.

4 Click OK.

Moving the Focus of Control

Sometimes it is helpful to move the starting point of an FOC and all corresponding messages. If the FOC has an entry point message, you can move the message. Otherwise, follow these steps:

To move the FOC on a sequence diagram:

1 Select the first message from the FOC you want to move.

2 Press the ALT key.

3 Click the source message and move it to the desired location on a sequence diagram.

    The source FOC changes locations.

Nested Focus of Control

A nested Focus of Control is an FOC that resides on another FOC. Nested FOC allows you to distinguish exactly where a message starts and where it ends. If you want to add a message to an existing sequence diagram, the nested FOC feature helps you determine where to place it.


Object Construction and Destruction

Object Construction Markers

To model an object that existed before or at the start of a sequence, you create a new object or drag an element from the browser to a sequence diagram. By default, the object is placed at the upper left side of the diagram. Any objects that you subsequently add are placed as close as possible to where they are created or dropped if they are dropped between two other objects.

To model an object that is constructed during a sequence, you can create the object or drag and drop an element from the browser then drag it down to where to the point where it is created. Once you place the object, you can draw a message from the calling object to the new object. Once placed, you cannot move the object above the calling object's construction. If you move the object below the message that it sends to create another object, the other object moves lower as well. To uncouple an object from its caller (for example, to change which is the calling object) you must reassign the message from the caller by moving the head from the object to the lifeline or by deleting the message.

It isn't a requirement that a construction message be sent to an object since an object's position determines its construction. However, if you do use a message, it will extend from the lifeline of the caller object to the constructed object. For example:

Object Destruction Markers

A destruction marker is often accompanied by a return message from the destroyed object to the caller that initialized the sequence, but the message is optional. To create a destruction marker, select the destruction message type from the toolbar and place the cursor on the class that is destroyed. This places an X at the cursor and causes the lifeline and focus of control to end.


Creating Alternative Diagrams

The Create Collaboration Diagram command creates a collaboration diagram from information contained in the sequence diagram. The Create Sequence Diagram command creates a sequence diagram from information contained in the collaboration diagram. The Go to Sequence Diagram and Go to Collaboration Diagram commands traverse between an interaction's two representations.

Toggling Between Interaction Diagrams

When you work in either a collaboration or sequence diagram, it is possible to view the corresponding diagram by pressing the F5 key. For example, if you are working on a sequence diagram, you can press F5 and Rational Rose will automatically create a collaboration diagram with the same diagram name and model elements. If you make a change to one diagram and then press F5, the change will appear on the corresponding diagram as well.

Note: When toggling from a sequence diagram to a collaboration diagram, you may need to rearrange the collaboration diagram model elements.

Creating a Collaboration Diagram from a Sequence Diagram

To create a collaboration diagram from a sequence diagram, click anywhere on the sequence diagram and click Browse > Create Collaboration Diagram. Note that if this collaboration diagram already exists, the Browse menu will instead present the Go to Collaboration Diagram option.

Creating a Sequence Diagram from a Collaboration Diagram

To create a sequence diagram from a collaboration diagram, click anywhere on the collaboration diagram and click Browse > Create Sequence Diagram. Note that if this sequence diagram already exists, the Browse menu will instead present the Go to Sequence Diagram option. Class instances in the collaboration diagram are represented as objects in the sequence diagram.


Object Specification (Interaction Diagrams)

An object specification allows you to display and modify the properties and relationships of an object in the current model.

To display an Object Specification, double-click any icon representing an object, or click Browse > Specifications.

Specification Content

The Object Specification consists of the General tab.

Object Specification--General Tab

Figure 75 Object Specification--General Tab

Refer to the descriptions in the Introduction to Specifications chapter for information on the specification elements not covered in the following section.

Name

If you specify the name of the object's class in the Object Specification, the name must identify a class defined in the model.

Class

The Class field displays the name of the object's parent class. The default class for a newly created object is Unspecified.

The object will accept messages conveying the operations of its parent class, and the operations of the superclasses of its parent class.

If you subsequently delete the class from the model, its name will be displayed in parentheses. If you recreate the class or create a new class with the same name, the object becomes an instance of this class.

Persistence Field

Use these options to specify the object's persistence.

Table 12 Persistence Field Options
Type
Description
Persistent
The object exists after the termination of the program in which it was created.
Static
The object exists during the entire execution of a program.
Transient
The object is created and destroyed dynamically during the execution of a program.

To display an object's persistence in a collaboration diagram, right-click an icon representing the object, and click Show Persistence.

Multiple Instances Check Box

Select the Multiple Instances check box to indicate that this object represents multiple instances of the same class. When you select this field, the icon changes from one object to three staggered objects. The object group is considered one entity, but this icon indicates that several objects are involved.


Class Instance Specifications

A class instance places a representation of a class on a collaboration diagram.

To display a Class Instance Specification, double-click any icon representing a class instance, or click Browse > Specifications.

Specification Content

The Class Instance Specification consists of the General tab.

Class Instance Specification--General Tab

Figure 76 Class Instance Specification--General Tab

Refer to the descriptions earlier in this chapter or in the Introduction to Specifications chapter for information on the specification elements not covered in the following section.

Class

The class the element belongs to is displayed here. The default class for a newly created element is (Unspecified). If you specify an object's class in the Object Specification, the class name must identify a class defined in the model, or you may create a new class.

To create a new class through the Object Specification, click the scroll arrow to the right of the Class field. A list box will display all the possible class selections, including <New>. Double-click <New>. A Class Specification dialog box is displayed. Enter the information regarding the new class.

If you delete a class from the model after you have associated it with one or more objects, the class name is enclosed in parentheses. If you re-create the class or create a new class with the same name, the object becomes an instance of the new class.

You can set this field only through the dialog box.


Link Specification

A link is the path of communication between two objects. A link can exist between two objects, between an object and a class instance, or between an object and itself.

To display a Link Specification, double-click any icon representing a link, or click Browse > Specifications.

Specification Content

The Link Specification consists of the following tabs: General and Messages.

Link Specification--General Tab

Figure 77 Link Specification--General Tab

Refer to the descriptions in the Introduction to Specifications chapter for information on the specification elements not covered in the following section.

Assoc

The Assoc field lists any valid role(s) or association(s) tied to the classes belonging to the two objects.

Select an association from the drop-down list. The name of the role tied to the association is displayed beside the link on the diagram. The keys are displayed in brackets under the role, and the constraints are displayed in braces under the keys.

Supplier and Client Visibility

Visibility is the ability of one object to see another object.

You can specify the following visibility types for the supplier object, the client object or both.

Table 13 Supplier and Client Visibility Options
Type
Description
Unspecified (Default)
The object visibility has not been specified.
Field
The supplier object is visible because it is a field of the client.
Parameters
The supplier object is visible to the client because it is a parameter for one of the client's operations.
Local
The supplier is local to an operation of the client object.
Global
The supplier object is global to the client.

An object visibility adornment is a letter inside a box placed at the supplier end of the link. Each letter identifies the type of visibility used. The adornment box is either open (shared) or filled (unshared).

You can set link visibility through the Link Specification or through the shortcut menu. These fields correspond to visibility adornments displayed in the collaboration diagram.

The visibility adornment is placed at the appropriate end of the link. The unspecified object visibility does not have a corresponding visibility adornment. Use this adornment only when you need to document an important tactical decision.

Shared

If visibility is an important detail in your software model, use visibility adornments to show these details in a collaboration diagram.

Shared visibility indicates structural sharing of the given object; that is, the shared object's state can be altered through more than one path. Unshared visibility represents unique access given to the client object. When you create a link, unshared visibility is the default.

You can set the shared indicators in the Link Specification or by selecting a visibility value from the shortcut menu.

To toggle the shared indicator, select or clear the Shared check box below the appropriate visibility section.

Role

This field lists the role names tied to the selected associations. This is especially useful since many associations are not named. This field cannot be edited.

Note: The Link to Self Specification contains only the Name, Visibility, and Shared elements.

Link Specification--Messages Tab

Figure 78 Link Specification--Messages Tab

Refer to the descriptions in the Introduction to Specifications chapter for information on the specification elements not covered in the following section.

You can add a message either directly on the diagram or through Insert on the shortcut menu.

Icon

This left-most unlabeled field contains a small version of the link message icon indicating the direction of the message.

Sequence

This is a system-assigned, sequential message number.

Message Name

Click the item to see the Picklist box showing all available operations on the class. This is the only editable column on this tab.

Receiver

This is the object receiving the message.

Note: You can double-click every field except the icon field to display the message specification.


Message Specification

A message conveys an operation through a link between objects. A message's specification identifies the operation it conveys, its synchronization, its frequency, and its associated documentation.

To display a Message Specification, double-click any icon representing a message, or click Browse > Specifications.

Specification Content

The Message Specification consists of the following tabs: General and Detail.

Message Specification General Tab

Figure 79 Message Specification General Tab

Refer to the descriptions in the Introduction to Specifications chapter for information on the specification elements not covered in the following section.

Class

The Class field displays the name of the class to which the element belongs.

Message Specification--Detail Tab

Figure 80 Message Specification--Detail Tab

Refer to the descriptions in the Introduction to Specifications chapter for information on the specification elements not covered in the following section.

Synchronization

Use these options to specify concurrency semantics for the operation named in the Synchronization field.

Table 14 Synchronization Options
Type
Description
Simple (default)
The message has a single thread of control.
Synchronous
The operation proceeds only when the client sends a message to the supplier and the supplier accepts the message.
Balking
The client passes a message only if the supplier is immediately ready to accept the message; the client abandons the message if the supplier is not ready.
Timeout
The client abandons a message if the supplier cannot handle the message within a specified amount of time.
Asynchronous
The client sends a message to the supplier for processing and continues to execute its code without waiting for or relying on the supplier's receipt of the message.
Procedure Call
The entire nested sequence is completed before the outer level sequence resumes. This can be used with ordinary procedure calls as well as with concurrently active objects when one of them sends a signal and waits for a nested sequence of behavior to complete.
Return
Return from a procedure call. The return arrow may be suppressed since it is implicit at the end of an activation.

Frequency

Use these options to indicate whether the message is sent periodically or aperiodically.

Table 15 Frequency Options
Type
Description
Aperiodic
The message is sent at irregular intervals, or does not have a regular interval.
Periodic
The message is sent at regular intervals.


Rational Software Corporation  http://www.rational.com
support@rational.com
techpubs@rational.com
Copyright © 1993-2001, Rational Software Corporation. All rights reserved.
TOC PREV NEXT INDEX