Call Behaviors

In the course of simulating a process, you can enact the behaviors defined in an operation of either a Class (through its simulation Object) or an Activity in the model. In each case, you use JavaScript to call the behaviour.

Invoke the Behavior of a Class

A Class in your model defines a behavior that you want to simulate. This behavior is defined in the Behavior page of an Operation of the Class.

For example, the Class is intended to add two integers, through the Operation add. The integers in this case are parameters of the operation, defined by attributes of the Class, operand1 and operand2.




See also


In the Properties dialog for the Operation, select the Behavior page and edit the Behavior field to apply the JavaScript simulation objects (this or sim) to the behavior definition.

In the example:



return operand1+operand2


Dynamic Simulation with Javascript


Drag the Class onto your simulation Activity diagram and paste it as an Instance.

In the example, the Object is called calculator. For clarity, the element shown here is set to display inherited attributes and operations, and the behavior code, on the diagram.






On the simulation diagram, for the appropriate Action element, open the Properties dialog and on the Effect page type in the JavaScript to capture and simulate the Object's behavior.

In the example, the JavaScript defines a value that will be provided by simulating the behavior of the operation from the Object, as performed on two provided integers. That is:






Run the simulation, and observe its progress in the Locals window. Ultimately the Class behavior is reflected in the result of the simulation.

In the example: result = 16.



Invoke the Behavior of an Activity

An Activity element can have a behavior, defined by an operation in that element. As a simple example, an Activity might have an operation called Get Result, with the behavior return "ON";.

You can simulate this behavior in the Activity's child diagram (that is, internal to the Activity), with a JavaScript statement in the appropriate Action element's Effect field. In the example, this might be:



The statement invokes the parent Activity's operation GetResult and assigns the outcome of that operation's behavior to sim.result. You can observe the progress of the simulation and the result of simulating the behavior in the Locals window, where (in this example) the value result "ON" will ultimately display.