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

Chapter 7: Attributes and Operations

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

3.

Select <new operation>.

4.

Enter the new operation's name and details. (The options available on the operation specification window are discussed in earlier in this chapter.)

5.

Click OK to close the operation specification window and add the new operation.

To ensure each message has been mapped to an operation:

1.

Select Report → Show Unresolved Messages.

2.

Rose will display a list of all messages that have not yet been mapped to operations, as shown in Figure 7.19.

Figure 7.19: Show Unresolved Messages window

Exercise

In the exercise for Chapter 5, "Object Interaction," we created Sequence and Collaboration diagrams for the "Add Item to Shopping Cart" use case. These diagrams include messages that translate to some of the operations for the classes in our problem. In the Chapter 6 ("Classes and Packages") exercise, we diagrammed the classes on a Class diagram and packaged the classes. In this exercise, we'll add details to the classes, such as the operations for the class, including parameters and return types. We'll also add attributes to the classes.

Problem Statement

Once Karen had a Class diagram with the classes for the "Add Item to Shopping Cart" use case, she began to fill in the details. She chose C++ as a programming language, then proceeded to add operations. She went back and looked at the Sequence and Collaboration diagrams to help define operations. She copied the Sequence and Collaboration diagrams and added more details to them. First, she mapped each object to a class. Then, she mapped each message to an operation. This is the method she used to define her operations.

She also went back to the flow of events to identify attributes. She added the attributes Order Number and Customer Name to the Order class on the Class diagram. She also took a look at the order items. Because

295

Chapter 7: Attributes and Operations

there are many order items on a particular order and each has some information and behavior, she decided to model them as a class rather than an attribute of Order. To keep the model consistent, she updated the Sequence diagram, as shown in Figure 7.20.

Figure 7.20: Updated Sequence diagram

Just then, Bob came in with a requirement change.

"We need to start keeping track of the order date and order fill date. Also, we've got some new suppliers, and the procedure for restocking the inventory has changed quite a bit."

Karen first documented the new date requirements, and took a high−level look at the changes to the restocking procedures. Because she was currently working on the "Enter New Order" use case, she was

primarily concerned with how the procedural changes would affect this use case. She was planning to work on the "Restock Inventory" use case next month, and would worry about the details of the restocking procedures then. It turned out that the new procedures, while they drastically affected the "Restock Inventory" use case, didn't affect the "Enter New Order" use case.

The new date requirements necessitated the addition of a couple of new attributes to the Order class. With these added, the model again reflected the most current requirements.

Add Attributes and Operations

Add attributes and operations to the classes using the Add Item to Shopping Cart Class diagram. Add language−specific details to the attributes and operations. Set the options to display all attributes, all operations, and the operation signatures. Set the options to display the visibility using UML notation.

Exercise Steps:

Setup

1.

Select Tools → Options.

2.

Select the Diagram tab.

3.

Be sure the Show Visibility check box is checked.

4.

296

Chapter 7: Attributes and Operations

Be sure the Show Stereotypes check box is checked.

5.

Be sure the Show Operation Signatures check box is checked.

6.

Be sure the Show All Attributes and Show All Operations check boxes are checked.

7.

Be sure the Suppress Attributes and Suppress Operations check boxes are not checked.

8.

Select the Notation tab.

9.

Be sure the Visibility as Icons check box is not checked.

Create a Detailed Sequence Diagram

1.

Locate the Main Flow Sequence diagram for the "Add Item to Shopping Cart" use case in the browser.

2.

Double−click to open the diagram.

3.

Press Ctrl+A to select all elements of the diagram

4.

Press Ctrl+C to copy all elements of the diagram.

5.

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

6.

Select New → Sequence Diagram from the shortcut menu.

7.

Name the new sequence diagram Main Flow: Detailed.

8.

Double−click to open the diagram.

9.

Press Ctrl+V to paste all items of the previous diagram into the new diagram.

10.

Double−click the CartInterface object to open its specification.

11.

297

Chapter 7: Attributes and Operations

Select CartInterface as the class for the object.

12.

Click OK to close the specification.

13.

Repeat steps 10–12 to set the classes for the following objects:

CartMgr : CartMgr

ProductMgr : ProductMgr

ProductItems : ProductCollection

White Crew Socks : Product

CartItems : CartCollection

Add Operations

1.

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

2.

Double−click to open the diagram.

3.

Right−click the CartInterface class.

4.

Select New Operation from the shortcut menu.

5.

Enter the new operation as follows:

AddItem(ItemNo: Long): Boolean

6.

Click outside of the class to stop adding operations.

7.

Repeat steps 3–6 to add the following operations to the following classes:

To CartMgr, add AddItem(ItemNo: Long): Boolean

298

Chapter 7: Attributes and Operations

To ProductMgr, add GetProduct(ItemNo: Long) : Product

To CartCollection, add AddItem(NewItem: Product) : Boolean

To ProductCollection(FindProduct), add FindProduct(ItemNo: Long) : Product

Add Attributes

1.

Right−click the Product class.

2.

Select New Attribute from the shortcut menu.

3.

Enter the new attribute as follows:

ProductID: Long

4.

Press Enter.

5.

Enter the other new attributes as follows:

ProductDescription: String

ProductUnitPrice: Double

6.

Click outside of the class.

The Class diagram for the Add Item to Shopping Cart Class diagram, after the operations and attributes have been added, should appear as in Figure 7.21.

299