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

Chapter 5: Object Interaction

Once you've added all of the objects, the next step is to map each of the objects to classes. You can map the objects to existing classes or create new classes for the objects (see the earlier section titled "Mapping an Object to a Class"). Then, you map each of the messages in the diagram to an operation (see the earlier section titled "Mapping a Message to an Operation"). Finally, you go into the object and message specifications if you need to set things like object persistence, message synchronization, and message frequency.

Exercise

In this exercise, we'll build a Sequence and a Collaboration diagram to add an item to the shopping cart in our web−based e−commerce system.

Problem Statement

After talking with April and building the system use case model, Andy began looking at the particular functionality that the system would have to perform. Andy started a detailed analysis of the features needed. The "Add Item to Shopping Cart" use case was one with a higher priority to the users and one with a higher element of risk. To allow plenty of time to deal with the risks of this use case, Andy decided to tackle it first by creating a Sequence and a Collaboration diagram.

Create Interaction Diagrams

Create the Sequence diagram and Collaboration diagram to add an item to the shopping cart. Your completed Sequence diagram should look like Figure 5.24.

Figure 5.24: Sequence diagram to add an item to the shopping cart

This is just one of the diagrams you would need to model the full "Add Item to Shopping Cart" use case. This diagram shows what happens when everything goes right. You would need some additional diagrams to

195

Chapter 5: Object Interaction

model what happens when things go wrong, or when the user selects different options. Each alternate flow in the use case may be modeled in its own Interaction diagram.

Exercise Steps:

Setup

1.

Select Tools → Options.

2.

Select the Diagram tab.

3.

Be sure that Sequence Numbering, Collaboration Numbering, and Focus of Control are all checked.

4.

Click OK to exit the Options window.

Create the Sequence Diagram

1.

Right−click Add Item to Shopping Cart in the system use case model in the browser.

2.

Select New → Sequence Diagram.

3.

Name the new diagram Main Flow.

4.

Double−click the new diagram to open it.

Add Actor and Objects to the Diagram

1.

Drag the Customer actor from the browser onto the diagram.

2.

Select the Object button from the toolbar.

3.

Click near the top of the diagram to add the object.

4.

Name the new object Cart Interface.

5.

Repeat steps 3 and 4 to add the other objects to the diagram.

196

Chapter 5: Object Interaction

Cart Mgr

Product Mgr

Product Items

White Crew Socks

Cart Items

Add Messages to the Diagram

1.

Select the Object Message toolbar button.

2.

Drag from the lifeline of the Customer actor to the lifeline of the Cart Interface object.

3.

With the message selected, type Add white crew socks to cart.

4.

Repeat steps 2 and 3 to add additional messages to the diagram, as shown below.

Add white crew socks to cart (between Cart Interface and Cart Mgr)

Get white crew socks (between Cart Mgr and Product Mgr)

Find product (white crew socks) (between Product Mgr and Product Items)

Get product (between Product Items and White Crew Socks)

Add white crew socks to cart (between Cart Mgr and Cart Items)

5.

Select the Message to Self button from the toolbar.

6.

Below the last message, click on the lifeline of the Cart Items object to add a reflexive message.

7.

Name this new message Add white crew socks to cart.

197

Chapter 5: Object Interaction

Create a Collaboration Diagram

To create a Collaboration diagram from the Sequence diagram, you can press F5, or if you would rather create a Collaboration diagram from scratch, follow the steps outlined here.

Create the Collaboration Diagram

1.

Right−click Add Item to Shopping Cart in the system use case model in the browser.

2.

Select New Collaboration diagram.

3.

Name the new diagram Main Flow.

4.

Double−click the new diagram to open it.

Add Actor and Objects to the Diagram

1.

Drag the Customer actor from the browser onto the diagram.

2.

Select the Object button from the toolbar.

3.

Click anywhere inside the diagram to add the object.

4.

Name the new object Cart Interface.

5.

Repeat steps 2 through 4 to add the other objects to the diagram, as shown below.

Cart Mgr

Product Mgr

Product Items

White Crew Socks

Cart Items

198

Chapter 5: Object Interaction

Add Messages to the Diagram

1.

Select the Object Link toolbar button.

2.

Drag from the Customer actor to the Cart Interface object.

3.

Repeat steps 1 and 2 to add links between the following:

Cart Interface and Cart Mgr

Cart Mgr and Product Mgr

Product Mgr and Product Items

Product Items and White Crew Socks

Cart Mgr and Cart Items

4.

Select the Link Message toolbar button.

5.

Click on the link between Customer and Cart Interface.

6.

With the message selected, type Add white crew socks to cart.

7.

Repeat steps 4 through 6 to add additional messages to the diagram, as shown in Figure 5.25.

Add white crew socks to cart (between Cart Interface and Cart Mgr)

Get white crew socks (between Cart Mgr and Product Mgr)

Find product (white crew socks) (between Product Mgr and Product Items)

Get product (between Product Items and White Crew Socks)

199