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



See also


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




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.




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




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.




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



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




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


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.




Click on the Generate button to create the source code.




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