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

Chapter 8: Relationships

Figure 8.31: Role constraints

Exercise

In this exercise, we will add the relationships between the classes that participate in the "Add Item to Shopping Cart" use case.

Problem Statement

Once Karen had added the attributes and operations to the classes, she was nearly ready to generate code. First, though, she had to take a look at the relationships between the classes.

She examined the Sequence diagrams for any existing messages between two objects, which indicated the need for a relationship between the classes. Any classes that communicated in the Sequence diagram needed a relationship on the Class diagram. Once she identified the relationships, she added them to the model.

Adding Relationships

Add relationships to the classes that participate in the "Add Item to Shopping Cart" use case.

Exercise Steps:

Setup

1.

338

Chapter 8: Relationships

Locate the Add Item to Shopping Cart Class diagram in the browser.

2.

Double−click to open the diagram.

3.

Look for a Unidirectional Association button on the Diagram toolbar. If one does not exist, continue through step 5. Otherwise, skip to the next section of the exercise.

4.

Right−click the Diagram toolbar and select Customize from the shortcut menu.

5.

Add the button labeled Creates a Unidirectional Association to the toolbar.

Add Associations

1.

Select the Unidirectional Association toolbar button.

2.

Draw an association from the CartInterface class to the CartMgr class.

3.

Repeat steps 1 and 2 to draw the following associations:

From CartMgr to ProductMgr

From ProductMgr to ProductCollection

From ProductCollection to Product

From CartMgr to CartCollection

From CartCollection to CartItem

4.

Right−click the unidirectional association between the CartInterface class and the CartMgr class, near the CartInterface class.

5.

Select Multiplicity → Zero or One from the shortcut menu.

6.

Right−click the other end of the unidirectional association.

7.

339