Sequence and Collaboration and diagrams

Sequence nd Collaboration diagrams, sometimes called collectively interaction diagrams, are two of several diagrams you can use to model the dynamic aspects of a system or subsystem. Both depict interactions consisting of a set of objects, their relationships, and messages exchanged among them.

Collaboration diagrams emphasize the structural organization of objects, while Sequence diagrams emphasize the time ordering of messages. Collaboration diagrams are essentially graphs; Sequence diagrams are essentially tables with different objects and messages depicted across the X axis and increasing time down the Y axis. However, the two diagram are semantically equivalent: one type can convert to the other type with no loss of information. Together enables you to do this conversion with a simple mouse click.

Though semantically equivalent, the two diagrams do not necessarily show the same information. For example, Collaboration diagrams explicitly show how objects are linked, while in Sequence diagrams the links are implied. Message return values show in Sequence diagrams but not in Collaboration diagrams.

Creating and drawing Collaboration and Sequence diagrams

If you need to learn how to create new diagrams in a project, or the techniques for placing elements and drawing links, consult the User's Guide topics found under " Working with Diagrams: Basic Diagram Techniques" in the Table of Contents. See Related Topics below.

Generating a Sequence diagram from an Operation

A frequent use of the Sequence diagram is to model the dynamics of some Operation of a class. The system module Generate Sequence Diagram provides a simple, automated way to generate a Sequence diagram from an operation.

To generate a Sequence diagram from an operation:

  1. Open the Class diagram containing the class whose operation you want to model.

  2. Locate the desired class and the desired Operation.

  3. Right-click the Operation and choose Genrate Sequence Diagram from the speedmenu.

Together generates a new Sequence diagram in the same package as the source class, with the same name as the source operation, and opens it in the Diagram pane.


Note:This feature only works in products that support Java,
in projects where Java is the target programming language.


Content

Collaboration and Sequence diagrams both typically contain:

Together interaction diagrams also include Actors than can send and receive messages.

Working with Sequence diagrams

If you've not previously drawn Sequence diagrams using Together,  a few pointers may be in order.

Working with Collaboration diagrams


Converting to a different interaction diagram

A mentioned in the introduction above, Collaboration and Sequence diagrams are just different ways of viewing the same information. Together enables you to view either type of interaction diagram as the other type. However, when you create a new diagram, you must specify that it is either a Sequence diagram or a Collaboration diagram, and Together then tracks it as such. The diagram displays in the Explorer as the type of origin, and opens in that view. That is to say, if you create a Sequence diagram, it will always show in the Explorer, and open in the Diagram pane as a Sequence diagram. But you can view it as a Collaboration diagram.

To view an interaction diagram as the other type:

  1. Right-click on the diagram background.

  2. If the diagram is a Sequence diagram, choose View as Collaboration from the diagram speedmenu. If viewing a Collaboration diagram, the menu command is View as Sequence.

  3. Repeat this process to switch back and forth.

Note: You can also do this switch from the speedmenus of interaction diagrams in the Explorer.

Key elements and properties

Object

An object role in a Sequence diagram is shown as a vertical dashed line called the "lifeline". The lifeline represents the existence of the object at a particular time. If the object is created or destroyed during the period of time shown on the diagram, then its lifeline starts or stops at the appropriate point; otherwise it goes from the top to the bottom of the diagram. An object symbol is drawn at the head of the lifeline.

Key Object properties

Property

 Description

Name

Every object has a name to distinguish it from other classes. Name is a text string. You need only enter the simple name for Objects. The qualified name is used when you specify the Object's classifier (see instantiates).

Instantiates

Specifies the Object's classifier. You can either enter the value yourself, or pick the class from a dialog that lists all the resources available to the project.

When you apply this property, the Object displays its fully qualified name. The properties Inspector displays the Class tab in which you can access the properties of the Object's class.

Tip: You can also specify the classifier by selecting the Object in the diagram or the Explorer and calling Choose Class from its speedmenu.

Messages

A message is a communication between objects that conveys information with the expectation that action will ensue. The receipt of a message is a kind of event. A message is shown as a horizontal solid arrow from the lifeline of one object to the lifeline of another object. The message may also be drawn from and to the same object, representing a message from an object to itself. The arrow is labeled with the name of the message (operation or signal) and its argument values. The arrow may also be labeled with a sequence number to show the sequence of the message in the overall interaction. Sequence numbers are useful on the diagrams for identifying concurrent threads of control.

Key Message properties

Properties of Messages, and the labels these create on the diagram convey a great deal of information about the dynamics of the interaction, especially in Sequence diagrams. You won't necessarily set a value for every property: for example you wouldn't set Condition unless modeling some elementary branching.

Property

 Description

Label

Optional arbitrary identifier. For example, if the message is one that creates another Object, you could label it "create".

Number

Time-ordered sequence number. Value is automatically incremented as you draw Message links. You could modify this value for two or more Messages to reorder their time sequence.

Operation

If the Message is sent by an operation, you can identify it here. Enter a value or pick the operation from an explorer dialog listing your project resources. You can specify arguments and/or return value, if any, in those properties.

Condition

Normally a Boolean expression (e.g., errorCode > 0).

Iteration

Enter a value if the Message is iterative or sent on a given iteration

Creation

Check if the Message is one that creates the Object to which it is sent

Destruction

Check if the Message is one that destroys the Object to which it is sent

Synchronization

Specify how or whether the target Object waits for some result. Useful when modeling multiple threads of flow control.

Actor

The Actor enables you to create sequence diagrams that model how business workers interact with and handle business objects while performing the workflow of a realization of a business use-case.

The Actor in a Sequence diagram displays a lifeline and can exchange messages with other Actors and/or objects.

Tips and Tricks

Creating a Message-to-self

To create a message from an Object back to itself:

  1. Click on the Self Message button on the diagram's toolbar

  2. Click on the Object's life line at the point where you want the Message to appear

Creating a Message link that calls an operation

For such message links there is additional tab "Operation" in the Inspector and, if the Editor pane is visible, the operation's source code is displayed there.

To create a Message link that calls an operation:

  1. Create the Message link between two objects. Both objects must have their instantiates property set to point to a class.

  2. Select the message link.

  3. In the Inspector, go to the operation field and launch the picker dialog using the field's browse button to display the Choose Operation Name dialog. The dialog displays the operations of the receptor object's class.

  4. Select the operation and click OK. This renames the Message link to the operation's name.

If you now select this Message link, the Inspector displays two tabs. The tabs are MessageLink (Message link properties) and Operation. The Operation tab displays the operation's properties.

Reordering Message links

Select and drag Message links up and down the Object lifeline to reorder them. Reordering automatically updates the Message link numbers.

Sometimes you may wish to reorder message links keeping their sequential order and freeing the space between for new links. To do this, select a Message link line, press CTRL, and drag it . This shifts all succeeding links. If you select a number of Message links (pressing Ctrl key), then those selected are moved keeping their increments.

Related topics


Additional resources