RSS

Search Engine

Thursday, July 22, 2010

Models and Eclipse EMF

1.1. Data model

A data model, sometimes also called domain model, represents the data you want to work with. For example if you develop an online flight booking application you might model your domain model with objects like "Person", "Flight", "Booking" etc. The general recommendation is to model your data model independent of the application logic. This approach leads to classes with almost no logic and a lot of properties, e.g. Person would have the properties "firstName", "lastName", "Address", etc.

1.2. Eclipse EMF

Eclipse EMF can be used to model your domain model. EMF has a distinction between the meta-model and the actual model. The meta-model describes the structure of the model. A model is then the instance of this meta-model.

EMF uses XMI (XML Metadata Interchange) to persists the model definition.

This EMF meta-model definition can be defined based on:

  • A XMI document, using an XML or text editor

  • Java annotations

  • UML

  • XML Schema

Once the EMF meta-model is specified you can generate the corresponding Java implementations classes from this model. EMF provides the possibility that the generated code can be safely extended by hand.

1.3. Meta Models - Ecore and Genmodel

EMF is based on two meta-models; the Ecore and the Genmodel model. The Ecore metamodel contains the information about the defined classes.

  • EClass : represents a class, with zero or more attributes and zero or more references.

  • EAttribute : represents an attribute which has a name and a type.

  • EReference : represents one end of an association between two classes. It has flag to indicate if it represent a containment and a reference class to which it points.

  • EDataType : represents the type of an attribute, e.g. int, float or java.util.Date

The Genmodel contains additional information for the codegeneration, e.g. the path and file information. The genmodel contains also the control parameter how the coding should be generated.

The Ecore model shows a root object representing the whole model. This model has children which represents the packages, whose children represents the classes, while the children of the classes represents the attributes of these classes. EMF's meta model Ecore (roughly) corresponds to the EMOF (Essential MOF) subset of the MOF 2.0 standard.

1.4. Advantages of using EMF

With EMF you make your domain model explicit which helps to provide clear visibility of the model. EMF also provides change notification functionality to the model in case of model changes. EMF will generate interfaces and factory to create your objects; therefore it helps you to keep your application clean from the individual implementaiton classes.

Another advantages is that you can regenerate the Java code from the model at any point in time.

0 comments:

Post a Comment