Book a Demo

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

Prev Next

Generate Source Code

Generate Source Code banner

Source code generation is the process of creating programming code from a UML model. There are great benefits in taking this approach as the source code Packages, Classes and Interfaces are automatically created and elaborated with variables and methods.

Enterprise Architect can also generate code from a number of behavioral models, including StateMachine, Sequence and Activity diagrams. There is a highly flexible template mechanism that allows the engineer to completely tailor the way that source code is generated, including the comment headers in methods and the Collection Classes that are used.

From an engineering and quality perspective, the most compelling advantage of this approach is that the UML models and therefore the architecture and design are synchronized with the programming code. An unbroken traceable path can be created from the goals, business drivers and the stakeholder’s requirements right through to methods in the programming code.

Facilities

Facility

Description

See also

Languages

Enterprise Architect supports code generation in each of these software languages:

  • Action Script
  • Ada
  • ArcGIS
  • C
  • C# (for .NET 1.1, .NET 2.0 and .NET 4.0)
  • C++ (standard, plus .NET managed C++ extensions)
  • Delphi
  • Java (including Java 1.5, Aspects and Generics)
  • JavaScript
  • MFQL
  • MySql
  • PHP
  • Python
  • Teradata SQL
  • Visual Basic
  • Visual Basic .NET
  • WorkFlowScript

You can also generate Hardware Definition Language code in these languages:

  • VHDL
  • Verilog
  • SystemC

Elements

Code is generated from Class or Interface model elements, so you must create the required Class and Interface elements to generate from. All other types of element to contribute to the code (such as StateMachines or Activities) must be child elements of a Class.

Add attributes (which become variables) and operations (which become methods). Constraints and Receptions are also supported in the code.

Settings

Before you generate code, you should ensure the default settings for code generation match your requirements; 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 facilitates setting specific generation options for each of the supported languages.

Source Code Options Namespaces Modeling Conventions Language Options

Code Template Framework

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.

Code Template Customization

Local Paths

Local path names enable you to substitute tags for directory names.

Local Paths Local Paths Dialog

Behavioral Code

You can also generate software code from three UML behavioral modeling paradigms:

  • Interaction (Sequence) diagrams
  • Activity diagrams
  • StateMachine diagrams (using Legacy State Machine Templates in the code generation operations under 'Tasks')
  • StateMachine diagrams (using an Executable State Machine Artifact)
Code Generation - Interaction Diagrams Code Generation - Activity Diagrams Code Generation - StateMachines

Live Code Generation

On the 'Develop > Preferences > Options' drop-down menu, you have the option to update your source code instantly as you make changes to your model.

Preferences Panel

Tasks

When you generate code, you perform one or more of these tasks:

  • Generate a Single Class
  • Generate a Group of Classes
  • Generate a Package
  • Update Package Contents
Generate a Single Class Generate a Group of Classes Generate a Package Update Package Contents

Notes

  • Most of the tools provided by Enterprise Architect for code engineering and debugging are available in the Professional and higher editions of Enterprise Architect; Behavioral Code Generation is available in the Unified and Ultimate editions
  • When security is enabled you require the access permissions 'Generate Source Code and DDL' and 'Reverse Engineer from DDL and Source Code'

Learn more