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

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.

A UML State element showing entry and exit behavior.

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.



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

Keyboard Shortcuts

Alt+1 > Behavior

Set Behavior


  • 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'.

A screenshot from Sparx Systems Enterprise Architect showing a UML Class element that owns an Operation in the Project Browser.

A UML Activity diagram showing Action elements that are associated with behavior from Operations owned by Class elements.

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*/


               if (cond1)










          /*Activity element (Activity) not rendered*/

          public void Activity2()


               // behavior is an Activity


          public void Interaction()


               // behavior is an Interaction


     } //end Container

Learn more