The introductory article by Ken Hussey explains how to create UML2 models with the Eclipse editor and how to create them programmatically with Java code. Here we will use Groovy and the EMFBuilder.

We use the UMLFactory for the EMFBuilder.

We create a model as the root node and then we create two primitive types and store them in Groovy variables because we have to reference them later on.

We define an enumeration OrderStatus with three literals.

The following code snippet shows the definition of the classes Address and USAddress. All the attributes are defined as a Property. The primitive types stringPrimitiveType and intPrimitiveType defined above are used. The class USAddress is a subclass of the abstract class Address. This is expressed with the Generalization object.

Compare this code to the original code in the article! The code is much more concise and is a direct representation of the UML2 diagram. No auxiliary methods are needed.