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

Chapter 6: Classes and Packages

Switch Type (Union) is the variable used for the case statements generated for the class.

Working with Packages

A package is used to group together classes that have some commonality. In UML, a package is displayed with this symbol:

There are a few common approaches when packaging classes, but you can group the classes together however you'd like. One approach is to group the classes together by stereotype. With this approach, you have one package with your client page classes, one with your server page classes, one with your applets, and so on. This can be a helpful approach to take for deployment's sake—all the forms that will go on the client machine are already packaged together.

Another approach is to group the classes together by functionality. For example, you might have a package called Security, which holds all of the classes that deal with application security. You might have some other packages called Employee Maintenance, Reporting, or Error Handling. The advantage of this approach is in reuse. If you carefully group your classes together, you end up with packages that are fairly independent of one another. In this example, you can just pick up the Security package and reuse it in other applications.

Finally, you can use a combination of these approaches. Packages can be nested inside each other to further organize your classes. At a high level, you may group your classes by functionality to create your Security package. Within this package, you can have some other packages, grouping the security classes by functionality or stereotype.

Adding Packages

The next step in creating your model is adding some packages. Class packages are created in the Logical view of the browser.

To add an existing package to a Class diagram:

Drag the package from the browser onto the Class diagram.

To add a new package to a Class diagram:

1.

Select the Package toolbar button.

2.

Click anywhere inside the Class diagram to place the package.

3.

242

Chapter 6: Classes and Packages

Type the package name.

To add a package to the browser:

1.

Right−click Logical View in the browser. To create a package inside an existing package, right−click the existing package in the browser.

2.

Select New → Package.

3.

Type the name of the new package.

To move an item into a package:

In the browser, drag the item from its existing location to the new package.

Deleting Packages

You can delete a package from a Class diagram or from the entire model. If you delete a package from the model, the package and all of its contents will be removed.

To remove a package from a Class diagram:

1.

Select the package on the Class diagram.

2.

Press the Delete key.

Note that the package has been removed from the Class diagram, but still exists in the browser and on other Class diagrams.

To remove a package from the model:

1.

Right−click the package in the browser.

2.

Select Delete from the shortcut menu.

OR

1.

Select the package on a Class diagram.

2.

Select Edit → Delete from Model, or press Ctrl+D.

Warning

243