Prev Next

Operation Behavior

You can define the behavior of an operation in one of two ways:

  • As a text description consisting of pseudo-code, structured English or just simple text
  • As a reference to a behavior element, such as an Activity or Interaction, or to another operation

You can set an option to show the behavior text or reference on the depiction of the parent element on a diagram. In this State element example, the entry operation applies the behavior of the ActivityComp Activity, whilst the exit behavior is described in simple text.

You can also define initial code to be inserted into an operation Body when that operation is initially generated to file; after that initial generation the code is no longer used and, if other behaviors have been defined, they are applied instead. See the Initial Code Help topic.

Access

Ribbon

Design > Element > Properties > Properties : (in a diagram or the Project Browser, click on the operation) > Behavior

Keyboard Shortcuts

Alt+1 > Behavior

Set Behavior

Either:

  • In the 'Behavior' field, type the text or code description of the behavior, or
  • Click on the Element button to display the 'Select Behavior' dialog, then browse for and select the appropriate element or operation; when you click on the OK button, the fully qualified object name displays in the 'Behavior' field

If you want to use initial code, click on the 'Code' tab and enter the code in the field on that tab.

If you want the behavior to be shown on any diagram that the operation appears in, select the 'Show Behavior in Diagram' checkbox.

When you have defined the operation behavior, click on the Save button.

Delete behavior

If you have typed in a behavior description in free text, simply select and delete the text.

If you have selected another behavioral object, click on the Element button and select the '<none>' option at the foot of the 'Select Element' hierarchy.

Example of Associated Behavior

An operation of, for example, a Class can be associated with a behavior elsewhere in the model. The operation is then set as the specification of that associated behavior. In code generation, the behavior of the associated behavioral element is generated as the operation's code; in this illustration, op1 is associated with the Activity 'Activity'.

The generated code for op1 is as shown:

     package Behavior;

     public class Container {

          public Container() {

          }

          public void finalize() throws Throwable {

          }

          public void op1() {

          /*Activity element(Activity)'s behavior rendered as

               operation(op1)'s code*/

               //Action1;

               if (cond1)

               {

                    //Action2;

               }

               else

               {

                     //Action3;

               }

               //Action4;

          }

          /*Activity element (Activity) not rendered*/

          public void Activity2()

          {

               // behavior is an Activity

          }

          public void Interaction()

          {

               // behavior is an Interaction

          }

     } //end Container

Learn more