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

Chapter 8: Relationships

Select the desired dependency.

2.

Select Edit → Delete from Model.

OR

1.

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

2.

Select the Relations tab.

3.

Right−click the relationship.

4.

Select Delete from the shortcut menu.

Package Dependencies

Dependencies can be drawn between packages as well as classes. A package dependency, like a class dependency, is drawn as a dashed arrow. Figure 8.14 is an example of a package dependency.

Figure 8.14: Package dependency

A package dependency from package A to package B suggests that some class in package A has a unidirectional relationship to some class in package B. In other words, some class in A needs to know about some class in B.

This has reuse implications. If our dependencies look like this, package A depends on package B. Therefore, we can't just pick up package A and reuse it in another application. We would also have to pick up B and reuse it. Package B, on the other hand, is easy to reuse because it doesn't depend on anything else.

You can find package dependencies by examining the relationships on your Class diagram. If two classes from different packages have a relationship, their packages must have a relationship as well.

As you are creating package dependencies, try to avoid circular dependencies whenever possible. A circular dependency looks like Figure 8.15.

315

Chapter 8: Relationships

Figure 8.15: Circular dependency

This suggests that some class in A needs to know about some class in B, while some class in B needs to know about some class in A. In this case, neither package can be easily reused, and a change to one package may affect the other. We've lost some of the benefits of packaging classes with this approach—the packages are

too interdependent. To break circular dependencies, you can split apart one package into two. In our example, we can take the classes in B that A depends on, and move them to another package we'll call C. Now our package dependencies look like this:

Creating Package Dependencies

As you identify package dependencies, you can add them to your Rose model through a Class diagram. Typically, you will have one Class diagram which displays all of the packages and the relationships between them. As with class dependencies, you use the Dependency toolbar button to draw the relationships.

To create a package dependency on a Class diagram:

1.

Select the Dependency icon from the toolbox.

2.

Drag the dependency line from the dependent package to the other package.

OR

1.

Select Tools → Create → Dependency.

2.

Drag the dependency line from the dependent package to the other package.

316