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

Generate a Single Class

Before you generate code for a single Class, you:

·Complete the design of the model element (Class or Interface)
·Create Inheritance connectors to parents and Associations to other Classes that are used
·Create Inheritance connectors to Interfaces that your Class implements; the system provides an option to generate function stubs for all interface methods that a Class implements
 

Generate code for a single Class

Step

Action

See also

1

Open the diagram containing the Class or Interface for which to generate code.

 

 

2

Right-click on the required Class or Interface and select the Generate Code context menu option, or press F11.

The Generate Code dialog displays, through which you can control how and where your source code is generated.

 

 

3

In the Path field, click on the (  ...  )  (Browse) button and select a path name for your source code to be generated to.

 

 

4

In the Target Language field, click on the drop-down arrow and select the language to generate; this becomes the permanent option for that Class, so change it back if you are only doing one pass in another language.

 

 

5

Click on the Advanced button.

The Object Options dialog displays, providing subsets of the Source Code Engineering and code language options pages on the Options dialog.

 

Source Code Options

Language Options

 

6

Set any custom options (for this Class alone), then click on the Close button to return to the Generate Code dialog.

 

 

7

If you are generating Java, C++, C# or C code, the Use the New Statemachine Template option displays with the checkbox selected.

If you want to use the Legacy Statemachine code generation templates, deselect the checkbox .

 

 

Legacy State Machine Templates

8

In the Import(s) / Header(s) fields, type any import statements, #includes or other header information.

Note that in the case of Visual Basic this information is ignored; in the case of Java the two import text boxes are merged; and in the case of C++ the first import text area is placed in the header file and the second in the body (.cpp) file.

 

 

9

Click on the Generate button to create the source code.

 

 

10

When complete, click on the View button to see what has been generated.

Note that you should set up your default viewer/editor for each language type first; you can also set up the default editor on the Code Editors page of the Options dialog (Tools | Options | Source Code Engineering | Code Editors).

 

 

 
Editing Source Code

Learning Center topics

·(Alt+F1) | Enterprise Architect | Software Engineering | Generate Code | Generate a Single Class