Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Mastering UML with Rational Rose 2002.pdf
Скачиваний:
137
Добавлен:
02.05.2014
Размер:
9.68 Mб
Скачать

Chapter 5: Object Interaction

diagram.

Working with Messages

A message is a communication between objects in which one object (the client) asks another object (the supplier) to do something. By the time you generate code, a message will translate to a function call. In this example, one form is asking another to display itself:

Adding Messages to an Interaction Diagram

Once you have placed the objects on your Sequence or Collaboration diagram, the next step is to add the messages sent between the objects. On a Sequence diagram, messages can be added by drawing an arrow between the lifelines of two objects. On a Collaboration diagram, you must first add a link between two objects. Then you can add messages to the link.

Adding Messages to a Sequence Diagram

In a Sequence diagram, messages are drawn between the lifelines of the objects or from an object's lifeline to itself. Messages are shown in chronological order, from the top of the diagram to the bottom.

To add a message to a Sequence diagram:

1.

Select the Object Message button from the toolbar.

2.

Drag the mouse from the lifeline of the object or actor sending the message to the object or actor receiving the message, as shown in Figure 5.6.

Figure 5.6: Adding a message to a Sequence diagram

3.

175

Chapter 5: Object Interaction

Type in the text of the message.

To add a reflexive message to a Sequence diagram:

1.

Select the Message to Self toolbar button.

2.

Click on the lifeline of the object sending and receiving the message, as shown in Figure 5.7.

Figure 5.7: Adding a reflexive message to a Sequence diagram

3.

With the new message still selected, type in the text of the message.

Deleting Messages from a Sequence Diagram

As you work on your Sequence diagram, you may need to delete some of the messages that you've drawn. If you delete a message, Rose will automatically renumber all of the remaining messages.

To delete a message from a Sequence diagram:

1.

Select the message to be deleted.

2.

Select Edit → Delete from Model, or press Ctrl+D.

Reordering Messages in a Sequence Diagram

At times, you may want to reorder the messages in your Sequence diagram. In Rose, reordering messages is very easy to do; you simply drag and drop the message into its new location. As the messages are reordered, they will automatically be renumbered.

To reorder the messages in a Sequence diagram:

1.

Select the message to be moved (select the arrow, not the text).

2.

176

Chapter 5: Object Interaction

Drag the message up or down in the diagram. Rose will automatically renumber the messages as you reorder them.

Message Numbering in a Sequence Diagram

Although you read the diagram from top to bottom, you have the option of using numbers on each message to display the message order, as shown in Figure 5.8. Message numbering is optional on Interaction diagrams. By default, numbering is disabled for Sequence diagrams.

Figure 5.8: Message numbering on a Sequence diagram

To turn message numbering on or off:

1.

Select Tools → Options.

2.

Select the Diagram tab.

3.

Set the Sequence Numbering check box to on or off, as shown in Figure 5.9.

177

Chapter 5: Object Interaction

Figure 5.9: Message numbering check box

Viewing the Focus of Control in a Sequence Diagram

In a Sequence diagram, you have the option of showing the focus of control, which lets you know which object has control at a particular point in time. As shown in Figure 5.10, a small rectangle represents the focus of control. This is one of the differences between a Sequence and a Collaboration diagram; the focus of control is shown only on a Sequence diagram.

Figure 5.10: Focus of control on a Sequence diagram

To turn the focus of control on or off:

1.

Select Tools → Options.

2.

Select the Diagram tab.

3.

178