Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » Best practices in model-driven development using EMF
Best practices in model-driven development using EMF [message #523820] Mon, 29 March 2010 13:52 Go to next message
Maxim Frolov is currently offline Maxim FrolovFriend
Messages: 20
Registered: March 2010
Location: Aachen
Junior Member
Hello,

a new model driven project in my company is started and EMF is being considered for modelling of application domain and generating code for (at least) the persistency layer.
After a couple of weeks of research I still don't have a clear picture, what parts of EMF are to be used for modelling and code generation in the new project.

The application domain will consist of about 300 objects/classes with inheritance. The domain objects of the application will be persisted in a relational database (Oracle). An OR-Mapper is being considered.

I believe that the model-driven approach will improve code quality and speed-up the development.

The first big question is whether to model application domain using own Xtext grammar or Ecore metamodel.
Currently I don't see any benefits of Xtext grammar in my case.

If I would use Ecore metamodel directly, I would just create a model of my application domain directly. I would just create these 300 EClass'es in the Eclipse Ecore editor, give them a name, and create EProperty's and EReference's. I would also attach documentation to the classes using EAnnotation's. If I wanted to create data access layer (DAO) I also would add EOperation's to my EClass'es. Then I would create code (.java files) for the domain layer and DAO layer using EMF and Hibernate mappings using Teneo tool.

Using Xtext grammar forces me to go an indirect way: I would model my domain classes in a text-based grammar language which will be converted later to an Ecore based model anyway. With Ecore based model it is clear, that a domain object/class is mapped to an EClass which is mapped to a Java class and to a table in the database. With Xtext this mapping is not obvious.

Or do I miss some points where Xtext would offer more benefits compared to Ecore models in my situation?


The next big question is whether I need to create an additional metamodel?
I saw some examples on the web about modelling of domain objects, where first a metamodel is created from Ecore meta-metamodel like this:
DataModel 
    Entity: Entity [0..*]
Entity:
    attribute: Attribute [1..*]
    reference: EntityReference [0..*]
Attribute:
    name: EString
    type: EString
...

See EMF tutorial here: http://www.openarchitectureware.org/pub/documentation/4.3.1/ html/contents/emf_tutorial.html
The domain model itself is then defined from this metamodel. Then code generation is performed.

I don't see any benefits of this additional metamodel in my application. All my 'entities' are plain Ecore EClass'es, attributes are EAttributes and so on. If I would use additional 'DataModel' metamodel I would throw away build-in Java code generator and would need to create own templates for code generation.
I believe that 90% of all enterprise applications have similar structure like my application.
When is an additional metamodel of interest?

Generally speaking I miss some best practices in model-driven development using EMF.


Re: Best practices in model-driven development using EMF [message #523827 is a reply to message #523820] Mon, 29 March 2010 14:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Maxim,

Comments below.

Maxim wrote:
> Hello,
> a new model driven project in my company is started and EMF is being
> considered for modelling of application domain and generating code for
> (at least) the persistency layer.
> After a couple of weeks of research I still don't have a clear
> picture, what parts of EMF are to be used for modelling and code
> generation in the new project.
>
> The application domain will consist of about 300 objects/classes with
> inheritance. The domain objects of the application will be persisted
> in a relational database (Oracle). An OR-Mapper is being considered.
Teneo provides integration with EclipseLink so that should solve this
problem.
>
> I believe that the model-driven approach will improve code quality and
> speed-up the development.
Definitely.
>
> The first big question is whether to model application domain using
> own Xtext grammar or Ecore metamodel. Currently I don't see any
> benefits of Xtext grammar in my case.
If you want a human readable textual syntax then Xtext is the way to
go. If that doesn't matter, you can use Ecore directly.
>
> If I would use Ecore metamodel directly, I would just create a model
> of my application domain directly. I would just create these 300
> EClass'es in the Eclipse Ecore editor, give them a name, and create
> EProperty's and EReference's. I would also attach documentation to the
> classes using EAnnotation's. If I wanted to create data access layer
> (DAO) I also would add EOperation's to my EClass'es. Then I would
> create code (.java files) for the domain layer and DAO layer using EMF
> and Hibernate mappings using Teneo tool.
Yep.
>
> Using Xtext grammar forces me to go an indirect way: I would model my
> domain classes in a text-based grammar language which will be
> converted later to an Ecore based model anyway. With Ecore based model
> it is clear, that a domain object/class is mapped to an EClass which
> is mapped to a Java class and to a table in the database. With Xtext
> this mapping is not obvious.
>
> Or do I miss some points where Xtext would offer more benefits
> compared to Ecore models in my situation?
It's purely useful for defining textual syntax, but you can define such
syntax for an existing Ecore model you've defined in some other way.
>
>
> The next big question is whether I need to create an additional
> metamodel? I saw some examples on the web about modelling of domain
> objects, where first a metamodel is created from Ecore meta-metamodel
> like this:
>
> DataModel Entity: Entity [0..*]
> Entity:
> attribute: Attribute [1..*]
> reference: EntityReference [0..*]
> Attribute:
> name: EString
> type: EString
> ..
>
> See EMF tutorial here:
> http://www.openarchitectureware.org/pub/documentation/4.3.1/ html/contents/emf_tutorial.html
>
> The domain model itself is then defined from this metamodel. Then code
> generation is performed.
> I don't see any benefits of this additional metamodel in my application.
Such models tend to end up looking almost exactly like Ecore.
> All my 'entities' are plain Ecore EClass'es, attributes are
> EAttributes and so on. If I would use additional 'DataModel' metamodel
> I would throw away build-in Java code generator and would need to
> create own templates for code generation. I believe that 90% of all
> enterprise applications have similar structure like my application.
> When is an additional metamodel of interest?
When Ecore is a poor match for how you want to define your models and
when the artifacts generated from Ecore are a poor match for what you want.
>
> Generally speaking I miss some best practices in model-driven
> development using EMF.
No, you seem to have a good grip on it.
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Best practices in model-driven development using EMF [message #523844 is a reply to message #523827] Mon, 29 March 2010 15:15 Go to previous messageGo to next message
Maxim Frolov is currently offline Maxim FrolovFriend
Messages: 20
Registered: March 2010
Location: Aachen
Junior Member
Ed,

Thank you very much for response!

From your words I understand that there is only visual difference between modelling using Xtext grammars and defining Ecore models directly.
So this is purely a matter of taste whether to type definitions of models using Xtext grammar or to draw Ecore diagrams (or to type Ecore classes in XML (XMI) directly or to code models as Java classes with Ecore annotations).
Everything one can model with Xtext is possible to model with Ecore models directly and vice versa.

I think, Xtext offers some benefits if the models are under source control system: it's easier to use diff/merge tools.

Ed Merks wrote on Mon, 29 March 2010 10:17

> When is an additional metamodel of interest?
When Ecore is a poor match for how you want to define your models and
when the artifacts generated from Ecore are a poor match for what you want.

Are there any examples about such situations?
Re: Best practices in model-driven development using EMF [message #523872 is a reply to message #523844] Mon, 29 March 2010 16:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Maxim,

Comments below.

Maxim wrote:
> Ed,
>
> Thank you very much for response!
>
> From your words I understand that there is only visual difference
> between modelling using Xtext grammars and defining Ecore models
> directly. So this is purely a matter of taste whether to type
> definitions of models using Xtext grammar or to draw Ecore diagrams
> (or to type Ecore classes in XML (XMI) directly or to code models as
> Java classes with Ecore annotations).
> Everything one can model with Xtext is possible to model with Ecore
> models directly and vice versa.
>
> I think, Xtext offers some benefits if the models are under source
> control system: it's easier to use diff/merge tools.
True, though things like EMF compare can convert the textual form back
to a model and then do the comparison based on the model.
>
> Ed Merks wrote on Mon, 29 March 2010 10:17
>> > When is an additional metamodel of interest?
>> When Ecore is a poor match for how you want to define your models and
>> when the artifacts generated from Ecore are a poor match for what you
>> want.
>
> Are there any examples about such situations?
I suppose XML Schema itself is an example.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Best practices in model-driven development using EMF [message #524095 is a reply to message #523844] Tue, 30 March 2010 05:05 Go to previous message
Volker Wegert is currently offline Volker WegertFriend
Messages: 182
Registered: July 2009
Senior Member
Maxim <maxim.frolov@gmx.net> writes:
> Ed Merks wrote on Mon, 29 March 2010 10:17
>> > When is an additional metamodel of interest?
>> When Ecore is a poor match for how you want to define your models and
>> when the artifacts generated from Ecore are a poor match for what you want.
> Are there any examples about such situations?

Take a look at the RFC mapping DSL in http://rcer.sf.net - while the data
objects defined there are "only" POJOs, the DSL contains additional
information about mapping the contents to something else that would be rather
cumbersome to include into an Ecore file. (Plus, RCER currently works on POJOs
only - I still have to figure out how to address EMF-generated classes
properly in an Xtext DSL.)

HTH
Volker

--
* Volker Wegert * http://www.volker-wegert.de/contact *
"What will you do now?" said Susan. - "Lie", said Lu-Tze happily, "It's
amazing how often that works." (Terry Pratchett, Thief Of Time)
Re: Best practices in model-driven development using EMF [message #619496 is a reply to message #523827] Mon, 29 March 2010 15:15 Go to previous message
Maxim Frolov is currently offline Maxim FrolovFriend
Messages: 20
Registered: March 2010
Location: Aachen
Junior Member
Ed,

Thank you very much for response!

From your words I understand that there is only visual difference between modelling using Xtext grammars and defining Ecore models directly.
So this is purely a matter of taste whether to type definitions of models using Xtext grammar or to draw Ecore diagrams (or to type Ecore classes in XML (XMI) directly or to code models as Java classes with Ecore annotations).
Everything one can model with Xtext is possible to model with Ecore models directly and vice versa.

I think, Xtext offers some benefits if the models are under source control system: it's easier to use diff/merge tools.

Ed Merks wrote on Mon, 29 March 2010 10:17
> > When is an additional metamodel of interest?
> When Ecore is a poor match for how you want to define your models and
> when the artifacts generated from Ecore are a poor match for what you want.

Are there any examples about such situations?
Re: Best practices in model-driven development using EMF [message #619497 is a reply to message #619496] Mon, 29 March 2010 16:47 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Maxim,

Comments below.

Maxim wrote:
> Ed,
>
> Thank you very much for response!
>
> From your words I understand that there is only visual difference
> between modelling using Xtext grammars and defining Ecore models
> directly. So this is purely a matter of taste whether to type
> definitions of models using Xtext grammar or to draw Ecore diagrams
> (or to type Ecore classes in XML (XMI) directly or to code models as
> Java classes with Ecore annotations).
> Everything one can model with Xtext is possible to model with Ecore
> models directly and vice versa.
>
> I think, Xtext offers some benefits if the models are under source
> control system: it's easier to use diff/merge tools.
True, though things like EMF compare can convert the textual form back
to a model and then do the comparison based on the model.
>
> Ed Merks wrote on Mon, 29 March 2010 10:17
>> > When is an additional metamodel of interest?
>> When Ecore is a poor match for how you want to define your models and
>> when the artifacts generated from Ecore are a poor match for what you
>> want.
>
> Are there any examples about such situations?
I suppose XML Schema itself is an example.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Best practices in model-driven development using EMF [message #619498 is a reply to message #619496] Tue, 30 March 2010 05:05 Go to previous message
Volker Wegert is currently offline Volker WegertFriend
Messages: 182
Registered: July 2009
Senior Member
Maxim <maxim.frolov@gmx.net> writes:
> Ed Merks wrote on Mon, 29 March 2010 10:17
>> > When is an additional metamodel of interest?
>> When Ecore is a poor match for how you want to define your models and
>> when the artifacts generated from Ecore are a poor match for what you want.
> Are there any examples about such situations?

Take a look at the RFC mapping DSL in http://rcer.sf.net - while the data
objects defined there are "only" POJOs, the DSL contains additional
information about mapping the contents to something else that would be rather
cumbersome to include into an Ecore file. (Plus, RCER currently works on POJOs
only - I still have to figure out how to address EMF-generated classes
properly in an Xtext DSL.)

HTH
Volker

--
* Volker Wegert * http://www.volker-wegert.de/contact *
"What will you do now?" said Susan. - "Lie", said Lu-Tze happily, "It's
amazing how often that works." (Terry Pratchett, Thief Of Time)
Previous Topic:Best practices in model-driven development using EMF
Next Topic:[Announce] MoDELS 2010 Call for Papers
Goto Forum:
  


Current Time: Thu Mar 28 08:29:12 GMT 2024

Powered by FUDForum. Page generated in 0.03488 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top