Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
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 operation name. Select a visibility option from the list of icons that appears.

Adding Arguments to an Operation

Operation arguments, or parameters, are the input data the operation receives. An Add operation, for example, may take two arguments, X and Y, and add them together.

There are two pieces of information to supply for each argument. The first is the argument name. The second is its data type. On a Class diagram, the arguments and data types appear in parentheses after the operation name:

If you'd like, you can also specify a default value for each argument. If you include a default value, the UML notation is:

Operation name(argument1 : argument1 data type = argument1 default value) : operation return type

When you generate code, Rose will generate the operation name, arguments, argument data types, argument default values, and return type. Rose will also create comments if any documentation was added to the operation.

To add an argument to an operation:

1.

Open the operation specification window.

2.

Select the Detail tab.

3.

Right−click in the Arguments box, then select Insert from the menu.

4.

278

Chapter 7: Attributes and Operations

Enter the name of the argument, as shown in Figure 7.9.

Figure 7.9: Operation arguments

5.

Click on the Type column and enter the data type of the argument.

6.

Click on the Default column and enter the default for the argument, if desired.

To delete an argument from an operation:

1.

Open the operation specification window.

2.

Select the Detail tab.

3.

Right−click the argument to be deleted in the Arguments box, and then select Delete from the menu.

4.

Confirm the deletion.

Specifying the Operation Protocol

The operation protocol describes what operations a client may perform on the object, and in which order the operations must be executed. For example, if operation A should not be executed until operation B has been

279

Chapter 7: Attributes and Operations

executed, you can note this in the Protocol field of operation A. The information you enter here will not have an impact on what code is generated for the operation. The operation protocol screen is shown in Figure 7.10.

Figure 7.10: Operation protocol

To specify the operation protocol:

1.

Open the operation specification window.

2.

Select the Detail tab.

3.

Enter the protocol in the Protocol field.

Specifying the Operation Qualifications

This field lets you identify any language−specific qualifications for the operation. It will not affect the code generated for the operation.

To specify the operation qualifications:

1.

Open the operation specification window.

2.

Select the Detail tab.

3.

280

Chapter 7: Attributes and Operations

Enter the qualifications in the Qualification field.

Specifying the Operation Exceptions

The operation Exceptions field gives you a place to list the exceptions that the operation may throw. In some languages, the exception information will affect the code generated for the operation. For example, Figure 7.11 is some Java code generated with exception information.

Figure 7.11: Operation exceptions in generated code

To specify the operation exceptions:

1.

Open the operation specification window.

2.

Select the Detail tab.

3.

Enter the exceptions in the Exceptions field.

Specifying the Operation Size

The Size field is a place to note how much memory you expect the operation to require at runtime. To specify the operation size:

1.

Open the operation specification window.

2.

Select the Detail tab.

3.

Enter the size in the Size field.

Specifying the Operation Time

The operation time is the approximate amount of time you expect this operation to require as it executes. To specify the operation time:

1.

Open the operation specification window.

2.

Select the Detail tab.

3.

Enter the time in the Time field.

281