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

Chapter 10: Component View

Drag the dependency line from the Client component to the Supplier component.

OR

1.

Select Tools → Create → Dependency.

2.

Drag the dependency line from the Client component to the Supplier component.

To delete a component dependency:

1.

Select the desired component dependency.

2.

Press the Delete key.

OR

1.

Select the desired component dependency.

2.

Select Edit → Delete.

Exercise

In this exercise, we will create the Component diagram for the shopping cart application. At this point, we've identified the classes that are needed for the "Add Item to Shopping Cart" use case. As other use cases are built, new components will be added to the diagram.

Problem Statement

With the analysis and design completed, Dan, one of the members of the deployment team, created the Component diagrams. By now, the team had decided to use Java, so he set about creating the appropriate components for each class.

Figure 10.5 shows the main Component diagram for the entire system. This main diagram focuses on the packages of components you will create.

373

Chapter 10: Component View

Figure 10.5: Main Component diagram

Figure 10.6 includes all of the components in the Entities package. These are the components that will contain the classes in the Entities package in the Logical view.

Figure 10.6: Entities package Component diagram

Figure 10.7 includes the components in the Control package. These components will contain the classes in the Control package in the Logical view.

374

Chapter 10: Component View

Figure 10.7: Control package Component diagram

Figure 10.8 includes the components in the Boundaries package. These components will contain the classes in the Boundaries package in the Logical view.

Figure 10.8: Boundaries package Component diagram

Figure 10.9 shows all of the components in the system. We've named this diagram the System Component diagram. With this one diagram, you can see all of the dependencies between all of the components in the system.

375

Chapter 10: Component View

Figure 10.9: System Component diagram

Exercise Steps:

Create the Component Packages

1.

Right−click the Component view in the browser.

2.

Select New → Package.

3.

Name the new package Entities.

4.

Repeat steps 1–3 for packages Boundaries and Control.

Add the Packages to the Main Component Diagram

1.

Open the main Component diagram by double−clicking it.

2.

Drag the Entities, Boundary, and Control packages from the browser to the main Component diagram.

Draw Package Dependencies

1.

376

Chapter 10: Component View

Select Dependency from the toolbox.

2.

On the main Component diagram, click the Entities package.

3.

Drag the dependency to the Control package.

4.

Repeat steps 1–3 to add a dependency from the Control package to the Boundaries package.

Add the Components for the Packages and Draw Dependencies

1.

Double−click the Entities package in the main Component diagram to open the main Component diagram for the Entities package.

2.

Select Package Specification from the toolbox.

3.

Place the package specification on the diagram.

4.

Enter the name of the package specification as CartCollection.

5.

Repeat steps 2–4 to add the CartItem, ProductCollection, and ProductItem package specifications.

6.

Select Dependency from the toolbox.

7.

Click on the CartItem package specification.

8.

Drag the dependency line to the CartCollection package specification.

9.

Repeat steps 6−8 to add dependencies from the ProductItem package specification to the Product−Collection package specification and from the ProductItem package specification to the CartItem package specification.

10.

Use this method to create the following components and dependencies:

 

CartInterface package specification for the Boundaries package

 

 

CartMgr package specification for the Control package

377

Chapter 10: Component View

ProductMgr package specification for the Control package

ProductMgr package specification to CartMgr package specification for a dependency in the Control package

Create the System Component Diagram

1.

Right−click the Component view in the browser.

2.

Select New → Component Diagram from the pop−up menu.

3.

Name the new diagram System.

4.

Double−click the System Component diagram.

Place Components on the System Component Diagram

1.

If needed, expand the Entities component package in the browser to open the package.

2.

Click the CartItem package specification within the Entities component package.

3.

Drag the CartItem package specification onto the diagram.

4.

Repeat steps 2 and 3 to place the CartCollection, ProductItem, and ProductCollection package specifications on the diagram.

5.

Use this method to place the following components on the diagram:

CartInterface package specification in the Boundaries component package

CartMgr package specification in the Control component package

ProductMgr package specification in the Control component package

6.

Select Main Program from the toolbox.

7.

378

Chapter 10: Component View

Place a main program on the diagram and name it MainProgram.

Add Remaining Dependencies to the System Component Diagram

The dependencies that already exist are automatically displayed on the System Component diagram after you add the components. Next, we add the remaining dependencies.

1.

Select Dependency from the toolbox.

2.

Click the ProductCollection package specification.

3.

Drag the dependency line to the ProductMgr package specification.

4.

Repeat steps 1–3 to add the following dependencies:

CartCollection package specification to CartMgr package specification

CartMgr package specification to CartInterface package specification

CartInterface package specification to MainProgram task specification

Map Classes to Components

1.

In the Logical view of the browser, locate the ProductItem class in the Entities package.

2.

Drag the ProductItem class to the ProductItem component package specification in the Component view. This maps the ProductItem class to the ProductItem component package specification.

3.

Repeat steps 1–2 to map the following classes to components:

CartItem class to CartItem package specification

CartCollection class to CartCollection package specification

ProductCollection class to ProductCollection package specification

CartMgr class to CartMgr package specification

379