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

Chapter 6: Classes and Packages

When you delete a package from the model, all classes and diagrams within the package will also be deleted.

Exercise

In this exercise, we'll take the classes we created last time and group them into packages. Then we'll create some Class diagrams to show the classes in the system and the packages.

Problem Statement

From the Interaction diagrams, Andy could see that the system met the business needs of the company. So he spoke with Karen, the lead developer.

"Here are the Interaction diagrams for adding a new order."

"Great! I'll get going on development."

Karen took a look at the classes in the Rose model. She decided to group them together by stereotype. So, she created packages called Entities, Boundaries, and Control, and moved each class into the appropriate package. Then, she created a Class diagram in each package: a Main Class diagram to display the packages and an Enter New Order Class diagram to show all of the classes for that use case.

Creating a Class Diagram

Group the classes that we've identified so far into packages. Create a Class diagram to display the packages, Class diagrams to display the classes in each package, and a Class diagram to display all of the classes in the "Enter New Order" use case.

Exercise Steps:

Setup

1.

Select Tools → Options.

2.

Select the Diagram tab.

3.

Be sure the Show Stereotypes check box is selected.

4.

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

5.

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

Create Packages

1.

244

Chapter 6: Classes and Packages

Right−click Logical View in the browser.

2.

Select New → Package.

3.

Name the new package Entities.

4.

Repeat steps 1–3 to create a Boundaries package and a Control package.

At this point, the browser should look like Figure 6.15.

Figure 6.15: Packages for the shopping cart system

Create Main Class Diagram

1.

Double−click the Main Class diagram, directly underneath the Logical View in the browser, to open the diagram.

2.

Drag the Entities package from the browser to the diagram.

3.

Drag the Boundaries and Control packages from the browser to the diagram.

The Main Class diagram should look like Figure 6.16.

245

Chapter 6: Classes and Packages

Figure 6.16: Main Class diagram for the shopping cart system

Create Class Diagram with All Classes in the "Add Item to Shopping Cart" Use Case

1.

Right−click Logical View in the browser.

2.

Select New → Class Diagram.

3.

Name the new Class diagram Add Item to Shopping Cart.

4.

Double−click the Add Item to Shopping Cart Class diagram in the browser to open it.

5.

Select the Class toolbar button and add the following classes to the diagram: CartMgr, CartInterface, ProductMgr, Product, ProductCollection, CartCollection, and CartItem.

The Class diagram should look like Figure 6.17.

Figure 6.17: Add Item to Shopping Cart Class Diagram

Add Stereotypes to the Classes

1.

Right−click the CartInterface class in the diagram.

2.

246

 

Chapter 6: Classes and Packages

Select Open Specification from the shortcut menu.

3.

In the stereotype field, type Boundary.

4.

Click OK.

5.

Right−click the CartMgr class in the diagram.

6.

Select Open Specification from the shortcut menu.

7.

In the stereotype field, type Control.

8.

Click OK.

9.

Repeat steps 1–4 to assign the CartCollection, Product, ProductCollection, and CartItem classes the entity stereotype.

The Class diagram should look like Figure 6.18.

Figure 6.18: Stereotypes for classes in Add Item to Shopping Cart use case

Group Classes into Packages

1.

In the browser, drag the CartInterface class to the Boundaries package.

2.

Drag the CartMgr and ProductMgr classes to the Control package.

3.

247

Chapter 6: Classes and Packages

Drag the CartCollection, Product, ProductCollection, and CartItem classes to the Entities package.

The classes and packages in the browser are shown in Figure 6.19.

Figure 6.19: Classes and packages in the Add Item to Shopping Cart use case

Add Class Diagrams to Each Package

1.

In the browser, right−click the Boundaries package.

2.

Select New → Class Diagram.

3.

Name the new diagram Main.

4.

Double−click the new diagram to open it.

5.

Drag the CartInterface class from the browser to the diagram.

The Main Class diagram for the Boundaries package should look like Figure 6.20.

248

Chapter 6: Classes and Packages

Figure 6.20: Main Class diagram for Boundaries package

6.

Close the diagram.

7.

Right−click the Entities package in the browser.

8.

Select New → Class Diagram.

9.

Name the new diagram Main.

10.

Double−click the new diagram to open it.

11.

Drag the CartCollection, Product, ProductCollection, and CartItem classes from the browser to the diagram.

The Main Class diagram for the Entities package should look like Figure 6.21.

Figure 6.21: Main Class diagram for Entities package

12.

Close the diagram.

13.

Right−click the Control package in the browser.

14.

249