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 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)

Learn more