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

Chapter 8: Relationships

Figure 8.24: Static role

To classify an association as static:

1.

Right−click the desired end of the association to be static.

2.

Select Static from the pop−up menu.

OR

1.

Open the desired association's specification window.

2.

Select the Detail tab for the role to be static.

3.

Select the Static check box.

Using Friend Relationships

A friend relationship indicates that the Client class has access to the non−public attributes and operations of the Supplier class. You can set the friend property for an association, aggregation, dependency, or generalization. The source code for the Supplier class will include logic to allow the Client class to have friend visibility.

For example, say we have a unidirectional association from a Person class to a Company class, and we've set the Friend check box for the relationship. When we generate C++ code, the Company .h file will include the line "friend class Person." This suggests that the Person class has access to the non−public parts of the Company class.

To classify a relationship as a friend:

1.

Right−click the appropriate end of the desired relationship.

2.

Select Friend from the pop−up menu.

OR

1.

Open the desired relationship's specification window.

2.

Select the Role Detail tab for the appropriate end.

3.

332

 

Chapter 8: Relationships

Select the Friend check box.

Setting Containment

The Containment field determines whether the generated attributes of an aggregation will be contained by value or by reference. In an aggregation, the whole class will have attributes added for each of the part classes. Whether these attributes are by value or by reference is set here.

A by−value attribute suggests that the whole and the part are created and destroyed at the same time. For example, if there is a by−value aggregation between a Window class and a Button class, the Window and the Button are created and destroyed at the same time. In UML, a by−value aggregation is shown with a filled diamond, as shown in Figure 8.25.

Figure 8.25: By−value aggregation

A by−reference aggregation suggests that the whole and the part are created and destroyed at different times. If we have an EmployeeList class that is made up of Employees, a by−reference aggregation would suggest that the Employee may or may not be around in memory, and the EmployeeList may or may not be around in memory. If they are both there, they are related via an aggregation. The Employee and EmployeeList are created and destroyed at different times. A by−reference aggregation is shown with a clear diamond, as in Figure 8.26.

Figure 8.26: By−reference aggregation

To set containment:

1.

Right−click the desired end of the association to set containment.

2.

Select Containment from the pop−up menu.

3.

Select the containment as By Reference, By Value, or Unspecified.

OR

1.

Open the desired relationship's specification window.

2.

Select the Role Detail tab for the desired role.

3.

Select the containment as By Reference, By Value, or Unspecified, as shown in Figure 8.27.

333

Chapter 8: Relationships

Figure 8.27: Setting containment

Using Qualifiers

A qualifier is used to reduce the scope of an association. For example, we may have an association between a Person class and a Company class. Suppose we want to say that for a given value of Person ID, there are exactly two related companies. We can add a qualifier called Person ID to the Person class. The diagram would look like Figure 8.28.

Figure 8.28: Using a qualifier

To add a qualifier:

1.

Right−click the desired association at the end to add a qualifier.

2.

Select New Key/Qualifier from the pop−up menu.

3.

Enter the new qualifier's name and type.

334

Chapter 8: Relationships

OR

1.

Open the desired association's specification window.

2.

Select the Role Detail tab for the desired role.

3.

Right−click the Keys/Qualifiers box.

4.

Select Insert from the pop−up menu.

5.

Enter the new qualifier's name and type.

To delete a qualifier:

1.

Open the desired association's specification window.

2.

Select the Role Detail tab for the desired role.

3.

Right−click the qualifier to be deleted.

4.

Select Delete from the pop−up menu.

Using Link Elements

A link element, also known as an association class, is a place to store attributes related to an association. For example, we may have two classes, Student and Course. Where should the attribute Grade be placed? If it is inside the Student class, we will need to add an attribute to Student for every course the student is enrolled in. This can clutter the Student class. If we put the attribute in Course, we will need an additional attribute for every student enrolled in the course.

To get around this problem, we can create an association class. The attribute Grade, because it's more related to the link between a student and a course than to each individually, can be placed in this new class. UML notation for an association class is shown in Figure 8.29.

335