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

Chapter 8: Relationships

Deleting Package Dependencies

As with a class dependency, there are two ways to delete a package dependency—from a single Class diagram or from the entire model.

If you delete a package dependency, but classes from the two packages still have relationships to each other, you will have difficulty generating code. You can use the Report → Show Access Violations option to see if this has happened.

To delete a package dependency from a Class diagram:

1.

Select the desired package dependency.

2.

Press the Delete key.

OR

1.

Select the desired package dependency.

2.

Select Edit → Delete.

Aggregations

An aggregation is a stronger form of association. An aggregation is a relationship between a whole and its parts. For example, a FlightList might be made up of Flights. In UML, an aggregation is shown as a line connecting the two classes, with a diamond next to the class representing the whole, as shown in Figure 8.16.

Figure 8.16: Aggregation relationship

One class may have several aggregation relationships with other classes. For example, a Car class might have relationships to its many parts.

317

Chapter 8: Relationships

Like associations, aggregations can be reflexive, as shown in Figure 8.17. A reflexive aggregation suggests that one instance of a class is made up of one or more other instances of the same class. For example, when cooking, you may combine some ingredients, which form ingredients for other things. In other words, each ingredient can be made up of other ingredients.

Figure 8.17: Reflexive aggregation relationship

When you generate code for an aggregation, Rose will generate attributes to support the aggregation. In the Car example, the Car class will have attributes for the door, engine, tire, and all of the other parts in the aggregation relationship.

Creating Aggregations

Aggregations are created on the Class diagrams. To create an aggregation, you can use the Aggregation button on the Class Diagram toolbar.

To create an aggregation on a Class diagram:

1.

Select the Unidirectional Aggregation icon from the toolbox.

2.

Drag the aggregation line from the whole class to the part class.

OR

1.

Select Tools → Create → Aggregation.

2.

Drag the aggregation line from the whole class to the part class.

To create a reflexive aggregation on a Class diagram:

1.

Select the Unidirectional Aggregation icon from the toolbox.

2.

Drag the aggregation line from the class to somewhere outside of the class.

3.

Release the aggregation line.

4.

318

Chapter 8: Relationships

Drag the aggregation line back into the class.

OR

1.

Select Tools → Create → Aggregation.

2.

Drag the aggregation line from the class to somewhere outside of the class.

3.

Release the aggregation line.

4.

Drag the aggregation line back into the class.

To add documentation to the aggregation:

1.

Double−click the desired aggregation.

2.

Select the General tab.

3.

Enter documentation in the Documentation field.

OR

1.

Select the desired aggregation.

2.

Select Browse → Specification.

3.

Select the General tab.

4.

Enter documentation in the Documentation field.

To change a relationship to an aggregation on a Class diagram:

1.

Select the desired relationship.

2.

Select Edit → Change Into → Aggregation.

OR

1.

319

Chapter 8: Relationships

Open the relationship specification window for the desired relationship.

2.

Select the Role Detail tab.

3.

Select the Aggregate check box.

Deleting Aggregations

You can delete an aggregation either from a single Class diagram or from the entire model. Here we list the procedures for both.

To delete an aggregation from the diagram:

1.

Select the desired aggregation.

2.

Press the Delete key.

OR

1.

Select the desired aggregation.

2.

Select Edit → Delete.

Note Deleting an aggregation from the diagram does not delete it from the model. To delete an aggregation from the model:

1.

Select the desired aggregation.

2.

Press Ctrl+D.

OR

1.

Select the desired aggregation.

2.

Select Edit → Delete from Model.

OR

1.

Open the specification window for either class participating in the relationship.

2.

320