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

Chapter 7: Attributes and Operations

If you are using Rose notation for visibility, single−click the Rose visibility icon to the left of the attribute name. Select a visibility option from the list of icons that appears.

To change the visibility notation:

1.

Select Tools → Options.

2.

Select the Notation tab.

3.

Check the Visibility as Icons check box to use Rose notation, or uncheck it to use UML notation.

Note Changing this option changes only the diagrams. The browser will always use the icon notation.

Setting the Attribute Containment

The attribute's containment describes how the attribute is stored within the class. There are three containment options:

By value Suggests that the attribute is contained within the class. For example, if you have an attribute of type "string," the string is contained within the class definition.

By reference Suggests that the attribute is located outside the class, but the class has a pointer to it. For example, you may have an attribute of type "employee" within a Timecard class. The employee object itself is located outside of the timecard. The attribute inside the timecard is simply a pointer to this external object.

Unspecified Suggests that the containment has not yet been specified. You should specify either By Value or By Reference prior to generating code. When generating code, Rose will assume By Value if the containment is unspecified.

To set the attribute containment:

1.

Right−click the attribute in the browser.

2.

Select Open Specification from the shortcut menu. The class attribute specification window will appear.

3.

264

Chapter 7: Attributes and Operations

Select the Detail tab.

4.

Select the attribute's containment: By Value, By Reference, or Unspecified. By default, all attributes are set to an unspecified containment.

Making an Attribute Static

When an attribute is added to a class, each instance of the class will receive its own copy of the attribute. For example, let's look at our Employee class. At runtime, we may instantiate three employees: John Doe, Bill Jones, and Jane Smith. Each of these three objects has its own copy of the attribute Salary.

A static attribute is one that is shared by all instances of a class. Returning to the previous example, if Salary was a static attribute, it would be shared by John, Bill, and Jane. When an attribute is marked as static, it will be underlined on the Class diagram. In this example, the Salary attribute is static:

To make an attribute static:

1.

Right−click the attribute in the browser.

2.

Select Open Specification from the shortcut menu. The class attribute specification window will appear.

3.

Select the Detail tab.

4.

Select the Static check box to mark the attribute as static. Rose will underline the attribute name on the Class diagram.

Specifying a Derived Attribute

A derived attribute is one that is created from one or more other attributes. For example, a Rectangle class

265