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

Chapter 8: Relationships

Figure 8.21: Relationship specification window

To set a relationship stereotype:

1.

Open the desired relationship's specification window.

2.

Select the General tab.

3.

Enter the stereotype in the Stereotype field.

Using Roles

Role names can be used instead of relationship names in associations or aggregations to describe the reason the relationship exists. Returning to our Person and Company example, we can say that a Person playing the role of an employee is related to a Company. Role names are typically nouns or noun phrases, and are shown next to the class playing the role. Typically, you would use either a relationship name or a role name, but not both. Like relationship names, role names are optional, and are only used when the purpose of the relationship is not obvious. Figure 8.22 shows an example of roles.

328

Chapter 8: Relationships

Figure 8.22: Roles in a relationship

You can add documentation to a role using the relationship specification window. Any documentation you add to a role will be generated as a comment when you generate code. To view the role on the diagram, right−click the relationship and select the Role Name option, as shown in Figure 8.23.

Figure 8.23: Setting role documentation

To set a role name:

1.

Right−click the desired association on the end to be named.

2.

Select Role Name from the shortcut menu.

3.

Type in the role name.

OR

1.

Open the desired association's specification window.

2.

Select the Role General tab for the role to be named.

3.

Enter the role name in the Role field.

329

Chapter 8: Relationships

To add role documentation:

1.

Open the desired association's specification window.

2.

Select the Role General tab for the desired role.

3.

Enter the documentation in the Documentation field.

Setting Export Control

In an association relationship, Rose will create attributes when you generate code. The visibility of the generated attributes is set through the Export Control field. As with other attributes, there are four visibility options:

Public Indicates that the attribute will be visible to all other classes

Private Indicates that the attribute is not visible to any other class

Protected Suggests that the attribute is visible only to the class and its subclasses

Package or implementation Means that the attribute is visible to all other classes in the same package

In a bidirectional relationship, you can set the export control of two attributes, one created at each end of the relationship. In a unidirectional relationship, only one will need to be set. The export control can be set using the Role A General and Role B General tabs of the relationship specification window.

330

Chapter 8: Relationships

To set export control for a role:

1.

Right−click the desired role's name.

2.

Select Export Control from the shortcut menu.

OR

1.

Open the desired relationship's specification window.

2.

Select the Role General tab for the desired role.

3.

Set the export control to Public, Protected, Private, or Implementation.

Using Static Relationships

As we mentioned earlier, Rose will generate attributes for association and aggregation relationships. A static attribute is one that is shared by all instances of a class. You use the Static field to determine whether or not the generated attributes will be static.

If you set one of the roles to be static, the associated attribute that is generated will be static. On the Class diagram, the static role will appear with a dollar sign ($) in front of it, as shown in Figure 8.24.

331