Question

I'm getting to grips with EMF and I'd like to check if a concept I have in my head is accurate.

I understand that one can create an EMF model in Eclipse and then use this to generate Java code.

I further understand that the model can be serialised to disk and then back again, but I don't understand the use of this.

Surely the model file itself can just be saved? Is there an obvious use case for serialization?

Was it helpful?

Solution

I think, you're confusing the two terms: "meta-model" and "model" here.

An EMF model is in fact a meta-model: it is the description of a model that can hold data. An EMF model/meta model can be represented in many different formats. For EMF, we usually use either .ecore/.genmodel or .xcore files.

From the EMF model/meta-model you can generate Java code that represents the model and the operations on the model. Seen from a theoretical level, the EMF model and the Java code are equal as they represent the same information.

With the generated Java code you can instantiate objects to hold model data. These data can then be saved to disk in a number of different formats. EMF can automatically provide the code needed to serialise the data of a model to disk in XML and back. (Actually, there are no generated code involved - it is all based on the description of your model in the ...Factory class). It is rather easy to implement other formats, such JSON or database schemas.


An example:

Assume that you have used EMF to describe a model for a bike (wheels, handlebar, frame, saddle, etc). From the EMF model you can generate Java classes that can describe the same bikes in terms of objects and relations between these.

You can now instantiate a number of different bikes in the model by creating/constructing and connecting the object of the Java classes.

These bikes can then be serialised as XML and back, so you can save the bikes to disk.


With MDA (Model Driven Architecture), we actually talk about 4 levels of models:

  • M0 is normally the physical artifact. E.g. a bike or a bill on paper.
  • M1 is the representation of the physical artifact - this is the model
  • M2 is the description of the model - the meta-model - in this case a EMF based model that describes the entities, relations and attributes of the model
  • M3 is the description of the description of the model - the meta-meta-model - which in fact can be represented in EMF as well. The information you find in the .ecore file and in the ...Package class are represented in M3 models as they describe M2 models.

The later really only matters to those of us, that teach MDA... In you normal work, you really only need to think of M0, M1 and M2...

OTHER TIPS

Serialization refers to persisting content of your model instance (your data). You can serialize to XML, JSON, database, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top