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

Chapter 7: Attributes and Operations

Right−click the operation in the browser.

2.

Select Open Specification from the shortcut menu.

3.

Enter the operation documentation in the DocComment area of the operation specification window.

OR

1.

Open the class specification window for the operation's class.

2.

Select the Operations tab.

3.

Select the operation.

4.

Type the operation documentation in the documentation window.

Deleting Operations

If you need to delete an operation, you can do so through a Class diagram or the browser. When an operation is deleted from one diagram, it is automatically removed from the entire model, including any other diagrams on which it appeared.

When deleting an operation, be sure to keep the model consistent. You may have used the operation in a Sequence or Collaboration diagram. If you delete the operation, it will be automatically converted into a message on all Sequence and Collaboration diagrams. Be sure to update the Sequence or Collaboration diagram appropriately.

To determine which diagrams reference an operation:

1.

Open the class specification window (or standard specification window in 98i) for the operation's class.

2.

Select Browse → Show Usage at the bottom of the dialog box.

To delete an operation from a class:

1.

Right−click the operation in the browser.

2.

Select Delete from the shortcut menu.

OR

1.

271

Chapter 7: Attributes and Operations

Select the operation on a Class diagram.

2.

Use the Backspace key to erase the operation name and signature from the diagram.

3.

Single−click anywhere on the diagram.

4.

Rose will confirm the deletion before the operation is removed.

OR

1.

Open the class specification window for the operation's class.

2.

Select the Operations tab.

3.

Right−click the operation you want to delete.

4.

Select Delete from the shortcut menu.

5.

Rose will confirm the deletion before the operation is removed.

Setting Operation Specifications

In the operation specifications, you can set details such as the operation parameters, return type, and visibility. In the next several sections, we'll take a look at each specification.

All of the specifications are viewed or changed on the operation specification window, as shown in Figure 7.7.

272

Chapter 7: Attributes and Operations

Figure 7.7: Operation specification window

To open the operation specifications:

1.

Right−click the operation in the browser.

2.

Select Open Specification from the shortcut menu.

OR

1.

Open the class specification window for the operation's class.

2.

Select the Operations tab.

3.

Double−click the appropriate operation.

Note In the following sections, if you are working with a Java, COM, or CORBA class, the specification window will be different. To open the standard specifications, right−click and then select Open Standard Specification from the shortcut menu.

273

Chapter 7: Attributes and Operations

Setting the Operation Return Class

The return class of an operation is the data type of the operation's result. For example, say we have an operation called Add, which takes as parameters two strings, X and Y. The operation will convert X and Y to integers, add them, and return the result as an integer. The return class of Add will be "integer."

When specifying the return class, you can either use built−in data types of your programming language—such as string, char, or integer—or use classes that you have defined in your Rose model.

To set the operation return class:

1.

Right−click the operation in the browser.

2.

Select Open Specification from the shortcut menu.

3.

Select a return class from the drop−down list box, or enter a new return type.

OR

1.

Select the operation on a Class diagram.

2.

After the operation name, enter a colon, followed by the return type. For example, if you have an operation called Print that should return an integer, your Class diagram will look like this:

Setting the Operation Stereotype

As with other model elements, operations can be stereotyped to classify them. As discussed above, there are four commonly used operation stereotypes:

Implementor Operations that implement some business logic.

Manager Constructors, destructors, and memory management operations.

Access Operations that allow other classes to view or edit attributes. Typically, these are named Get<attribute name> and Set<attribute name>.

Helper Private or protected operations used by the class but not seen by other classes.

274

Chapter 7: Attributes and Operations

Setting stereotypes for operations isn't required to generate code. However, stereotypes can help improve the understandability of the model. Also, they can help you to be sure that you haven't missed any operations.

To set the operation stereotype:

1.

Right−click the operation in the browser.

2.

Select Open Specification from the shortcut menu. Rose will open the operation specification window.

3.

Select a stereotype from the drop−down list box or enter a new stereotype.

OR

1.

Select the operation in the browser.

2.

Single−click the operation again to edit the name. Before the name, the double angle bracket characters (<<>>) will appear:

3.

Type the stereotype between the brackets.

275

Chapter 7: Attributes and Operations

Setting the Operation Visibility

As we discussed before, visibility has to do with how information and behavior is encapsulated in a class. There are four visibility options for operations. (To familiarize yourself with the way these are represented visually, see Table 7.2.)

Public Suggests that the operation is visible to all other classes. Any other class can request that the operation be executed.

Private Means that the operation is not visible to any other class.

Protected Suggests that the class and any of its descendants have access to the operation.

Package or implementation Indicates that the operation is public, but only to classes in the same package.

While attributes are typically private or protected, operations may be public, private, protected, or package. When making this decision, think about what other classes, if any, will need to know that the operation exists. When you generate code, Rose will generate the appropriate visibility. For example, the code generated for the class above is shown in Figure 7.8.

276

Chapter 7: Attributes and Operations

Figure 7.8: Operation visibility in generated code

As mentioned earlier in this chapter, you can use either UML or Rose notation on a Class diagram. See the upcoming numbered steps for a description of how to switch between these two notations. Refer to Figure 7.4 to see a class using UML visibility notation and to Figure 7.5 to see the same class using Rose visibility notation. To revisit a summary of the possible visibility options, including their Rose and UML notations, see Table 7.2.

To set the operation visibility:

1.

Right−click the operation in the browser.

2.

Select Open Specification from the shortcut menu. The Operation Specification window will appear.

3.

In the Export Control field, select the operation's visibility: Public, Protected, Private, or Implementation. By default, all operations have public visibility.

OR

1.

Select the operation on a Class diagram.

2.

If you are using UML notation for visibility, single−click the icon (+, −, or #) next to the operation. Select a visibility option from the list of Rose visibility icons that appears.

3.

277