Generate Source Code

Return to Introduction  Previous page  Next page

Generating source code (forward engineering) takes the UML Class or Interface model elements and creates a source code equivalent for future elaboration and compilation. By forward engineering code from the model, the mundane work involved with having to key in Classes and attributes and methods is avoided, and symmetry between model and code is ensured.

Code is generated from Class or Interface model elements, so you must create the required Class and Interface elements to generate from. Add attributes (which become variables) and operations (which become methods).

Before you generate code, you should ensure the default settings for code generation match your requirements. The default generation settings are located in the Source Code Engineering page of the Options dialog (select the Tools | Options | Source Code Engineering menu option). Set up the defaults to match your required language and preferences. Preferences that you can define include default constructors and destructors, methods for interfaces and the Unicode options for created languages.  Languages such as Java support namespaces and can be configured to specify a namespace root.  In addition to the default settings for generating code, Enterprise Architect supports the following code languages with their own specific code generation options:

·C
·C# (for both .NET 1.1 and .NET 2.0)
·C++ (standard, plus .NET managed C++ extensions)
·Java (including Java 1.5, Aspects and Generics)
·PHP

The Code Template Framework (CTF) enables you to customize the way Enterprise Architect generates source code and also enables generation of languages that are not specifically supported by Enterprise Architect.

Before generating code, you should also familiarize yourself with the way Enterprise Architect handles local path names. Local path names enable you to substitute tags for directory names (eg. %SRC% = C:\Source).

When you have completed the design of your classes, you can generate source code.

See Also