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

Chapter 8: Relationships

Select the Relations tab.

3.

Right−click the relationship.

4.

Select Delete from the shortcut menu.

Dependencies

A dependency relationship shows that a class references another class. Therefore, a change in the referenced class specification may impact the using class. When there is a dependency between two classes, Rose does not add any attributes to the classes for the relationship, which is one of the differences between an association and a dependency.

Returning to our example above, assume there is a dependency relationship between Flight and Customer. A dependency relationship is shown as a dashed arrow, as shown in Figure 8.12.

Figure 8.12: Dependency relationship

When we generate code for these two classes, attributes will not be added to either class for the relationship, as shown in Figure 8.13. However, any language−specific statements needed to support the relationship will be generated. For example, in C++, the necessary #include statements will be included in the generated code.

311

Chapter 8: Relationships

Figure 8.13: Code generated for a dependency relationship

The implication here is that Flight will need some other way to know that Customer exists. The direction of the arrow indicates that Flight depends on Customer. In other words, there is a Sequence or Collaboration diagram in which Flight sends a message to Customer. Had there been a regular association between these two, Flight would have a Customer attribute. To send a message to Customer, Flight would just look at its own Customer attribute.

With a dependency, however, Flight won't have a Customer attribute. It therefore has to find out about Customer some other way. There are three ways it can know about Customer. Customer could be global, in which case Flight would know it exists. Or, Customer could be instantiated as a local variable inside an operation of Flight. Finally, Customer could be passed in as a parameter to some operation inside Flight. When there is a dependency, one of these three approaches must be taken.

Although we are now at the detailed coding level, this decision may affect the model. We may need to add an argument to an operation of Flight.

312

Chapter 8: Relationships

The second difference between an association and a dependency lies in the direction. Associations can be bidirectional, but dependencies are unidirectional. Dependencies are also used for relationships between packages and between components. This will be discussed later in this chapter.

Creating Dependencies

After you've added associations, you may want to revisit them to see if any should be dependencies instead. If so, you can change the relationship from an association to a dependency using the method outlined below. (This is preferred if you have an association displayed in several diagrams, because Rose will change the association globally.)

To create a new dependency, you can use the Dependency icon on the Class Diagram toolbar.

To create a dependency on a Class diagram:

1.

Select the Dependency icon from the toolbox.

2.

Click the class to be dependent.

3.

Drag the dependency line to the other class.

OR

1.

Select Tools → Create → Dependency.

2.

Click the class to be dependent.

3.

Drag the dependency line to the other class.

To add documentation to a dependency:

1.

Double−click the desired dependency.

2.

Select the General tab.

3.

Enter documentation in the Documentation field.

OR

1.

313

Chapter 8: Relationships

Select the desired dependency.

2.

Select Browse → Specification.

3.

Select the General tab.

4.

Enter documentation in the Documentation field.

To change a relationship to a dependency on a Class diagram:

1.

Select the desired relationship.

2.

Select Edit → Change Into → Uses Dependency.

Deleting Dependencies

As with associations, there are two ways to delete a dependency. You can remove it from a single Class diagram or from the entire model. The following are the procedures for deleting a dependency.

To delete a dependency from the diagram:

1.

Select the desired dependency.

2.

Press the Delete key.

OR

1.

Select the desired dependency.

2.

Select Edit → Delete.

Note Deleting a dependency from the diagram does not delete it from the model. To delete a dependency from the model:

1.

Select the desired dependency.

2.

Press Ctrl+D.

OR

1.

314