Book a Demo

Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Prev Next

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 behavior.

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(int, int). The integers in this case are parameters of the operation, defined by attributes of the Class, operand1 and operand2.

Invoking the behavior of a class



See also


In the Properties window for the operation, select the 'Behavior' tab 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.

Instance of a class on an Activity 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.