| Free tutorials for Java, Eclipse and Web programming |
Version 2.0
Copyright © 2007-2011 Lars Vogel
01.01.2011
| Revision History | ||
|---|---|---|
| Revision 0.1 - 0.4 | 12.08.2007 - 13.09.2007 | Lars Vogel |
| Created | ||
| Revision 0.5 - 1.9 | 30.07.2008 - 01.01.2011 | Lars Vogel |
| bug fixes and enhancements | ||
Table of Contents
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.
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 provides a plugable framework to store the model information, the default uses XMI (XML Metadata Interchange) to persists the model definition.
EMF allows to create the meta-model via different means, e.g. XMI, Java annotations, UML or a XML Schema. The following description will use the EMF tools directly to create a EMF model.
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.
We said earlier that EMF has a meta-model. Actually EMF is based on two meta-models; the Ecore and the Genmodel model. The Ecore metamodel contains the information about the defined classes. 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 allows to define different elements.
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 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.
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.