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

Behavior Code

Behavior code is inserted into an operation Body when that operation is generated to file. This code is most useful when combined with Design Patterns; elements within a Pattern often require the same stub code. The behavior code is also useful for ensuring that the generated code can be directly compiled. The language-specific Patterns available from the web site resources include behavior code for some of the defined operations; this helps speed up the process of applying Patterns from model to implementation.

By default, the behavior code is not imported into the model during reverse engineering, but you can select to import the code by ticking the 'Include method bodies in model when reverse engineering' checkbox on the 'Source Code Engineering > Attribute/Operations' page of the 'Preferences' dialog.

You enter the behavior code through the Code Editor, which lists the operations within an element or within an Activity or StateMachine diagram and enables you to enter the behavior code for each operation individually. See the Editing Source Code Help topic.

On the Operation 'Properties' dialog, there is a 'Code' tab on which you can also enter the behavior code for the operation.  The code editing facilities are more streamlined but you can use context menu options to paste copied code in from elsewhere. You can also click on the Code Editor button to, again, create the code in the Code Editor. Bear in mind that switching to the Code Editor closes the operation 'Properties' dialog and does not transfer incompletely saved code, so you should save any code you create in the 'Properties' dialog before making the switch.

The 'Properties' dialog also has a 'Behavior' tab on which you can type pseudo-code or plain text to state what the operation does. This text is added to the element  code as a comment on the behavior code, and can be displayed on the parent element in a diagram. See the Operation Behavior Help topic.

Access

Before displaying the Behavior code, click on the required operation in the Browser window or a diagram.

Ribbon

Develop > Source Code > Behavior

Design > Element > Behavior

Context menu

Right-click on operation | Properties | Properties > Code   (if preferred, then : Code Editor)

Options

When selecting from the ribbon, you have three options for developing code:

  • Edit Behavior
  • Edit Internal Code
  • Edit (or View) Source Code

All three options display the Code Editor window, but show the appropriate features, code and editing options for the type of code identified by the option. Within the Code Editor you can right-click on the Operation and select to switch from whichever aspect you are working on to one of the other two.

Learn more