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

Initial Code

On the Behavior tab of the Operations dialog, you can use the Initial Code field to enter code to be inserted into an operation body when the operation is first generated to file. After this point, forward code generation and synchronization do not replace the existing operation code with the Initial Code field.

By default, the Initial Code field also is not imported into the model during reverse engineering, but you can select to import the field by selecting the Include method bodies in model when reverse engineering checkbox on the Options dialog.

This field is most useful when combined with UML Patterns. Elements within a pattern often require the same stub code. Notice that the language specific patterns available from include initial code for some of the defined operations. This helps speed up the process of applying patterns from model to implementation. The Initial Code section is also useful for ensuring that the generated code is directly compilable.

This example shows the contents of the Initial Code field for the Instance() operation of the Singleton element in the C# Singleton pattern:

Initial Code