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

Chapter 5: Object Interaction

Select the actor on the Interaction diagram.

2.

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

Note Deleting an actor from the diagram does not delete the actor from the model.

Working with Objects

The Sequence and Collaboration diagrams show you the objects that participate in one flow through a particular use case. Once the actor object has been added to the diagram, the next step is to add other objects. As we discussed above, you can find the objects that participate in a particular Sequence or Collaboration diagram by examining the nouns in the flow of events and scenario documents. After this step, we will go in and add the messages between the objects.

Adding Objects to an Interaction Diagram

One of the first steps in creating a Sequence or a Collaboration diagram is adding the objects. Look at the nouns from your flow of events and scenarios to start finding objects.

To add an object to a Sequence diagram:

1.

Select the Object toolbar button.

2.

Click in the location on the diagram where you want the object to reside. In a Sequence diagram, objects are arranged in a row near the top.

Note In Rose 2001A and 2002, you can move an object down from the top to the point at which it is created.

3.

Type the name of the new object.

4.

Once you have added the objects, you can rearrange them by dragging and dropping. You can insert an object between two existing objects by clicking between the two existing objects in step two.

To add an object to a Collaboration diagram:

1.

Select the Object toolbar button.

2.

Click in the location on the diagram where you want the object to reside. In a Collaboration diagram, objects can be located anywhere.

3.

Type the name of the new object.

168

Chapter 5: Object Interaction

Deleting Objects from an Interaction Diagram

As you build your Interaction diagrams, you may need to delete some of the objects. When you delete an object from the diagram, Rose will automatically delete any messages that start or end with that object and automatically renumber all of the remaining messages.

When you delete an object from a Sequence diagram, Rose will automatically delete the object from the Collaboration diagram but will not delete the corresponding class from the model. Similarly, when you delete an object from a Collaboration diagram, Rose will remove it from the Sequence diagram. If you change your mind, you can use the Undo option on the Edit menu.

To remove an object from a Sequence or Collaboration diagram:

1.

Select the object in the Sequence or Collaboration diagram.

2.

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

Note Deleting an object from the diagram does not delete the corresponding class from the model.

If you have several copies of an object on a single diagram and all copies have the same name and the same class, you can press Delete to remove one copy of the object. Pressing Ctrl+D or selecting Delete from Model will remove all copies.

Setting Object Specifications

There are a number of different fields that Rose provides to add some detail to the objects in your diagram. For example, you can set the object's name, its class, its persistence, and whether there are multiple instances of the object. You can also add documentation to the object in the object specification window, shown in Figure 5.5. Adding documentation to an object does not add the documentation to the class, and adding documentation to an object on one diagram does not add the documentation to the object on other diagrams. In the following sections, we'll take a look at each of the options available on the object specification window.

169

Chapter 5: Object Interaction

Figure 5.5: Object specification window

To open the object specifications:

1.

Right−click the object in the Sequence or Collaboration diagram.

2.

Select Open Specification from the shortcut menu.

OR

1.

Select the object in the Sequence or Collaboration diagram.

2.

Select Browse → Specification, or press Ctrl+B.

Naming an Object

Each object on a Sequence or Collaboration diagram should be given a unique name. However, for readability you may have multiple copies of a single object on the diagram, and in this case each copy will have the same name. While class names are very generic (Employee and Company, for example), object names are very specific (John Doe and Rational Software Corporation). On an Interaction diagram, you may have two objects that are instances of the same class. For example, in an inventory system, you may have one instance of a Part class, called Engine, which communicates with another instance of Part, called Carburetor. You can enter the name of each object on the diagram in the object specification window, or directly on the diagram.

To name an object:

1.

170

Chapter 5: Object Interaction

Right−click the object in the Sequence or Collaboration diagram.

2.

Select Open Specification from the shortcut menu.

3.

In the Name field, enter the object's name. You may also use this field to change the name of the object later on.

OR

1.

Select the object in the Sequence or Collaboration diagram.

2.

Right−click so that a cursor shows up in the object.

3.

Type the object name.

To add documentation to an object:

1.

Right−click the object in the Sequence or Collaboration diagram.

2.

Select Open Specification from the shortcut menu.

3.

In the Documentation field, you can enter documentation for the object.

OR

1.

Select the object in the Sequence or Collaboration diagram.

2.

Type the object documentation in the documentation window.

Mapping an Object to a Class

On a Sequence or Collaboration diagram, each object may be mapped to a class. For example, flight #1020 may be mapped to a class called Flight. In the object specification window, you can use the Class field to set the object's class. By default, the class will be set to (Unspecified).

When selecting a class for the object, you can either use an existing class from your model or create a new class for the object. In the procedures below, we describe both of these approaches.

By the time you are ready to generate code, all of the objects should be mapped to classes. To map an object to an existing class:

1.

171

Chapter 5: Object Interaction

Right−click the object in the Interaction diagram.

2.

Select Open Specification from the shortcut menu.

3.

In the Class drop−down list box, type the class name or select an option from the drop−down list box.

4.

Once you have mapped the object to a class, the class name will appear with the object name on the diagram, preceded by a colon. You can toggle the display of the class name by right−clicking the object and selecting Show Class.

OR

1.

Select the class in the Logical view of the browser.

2.

Drag the class from the browser to the object in the diagram.

3.

Once you have mapped the object to a class, the class name will appear with the object name on the diagram, preceded by a colon:

To remove an object's class mapping:

1.

Right−click the object in the Sequence or Collaboration diagram.

2.

Select Open Specification from the shortcut menu.

3.

In the Class drop−down list box, select (Unspecified).

To create a new class for the object:

1.

Right−click the object in the Sequence or Collaboration diagram.

2.

Select Open Specification from the shortcut menu.

3.

172