Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsBest practices in model-driven development using EMF
https://www.eclipse.org/forums/index.php/mv/msg/194600/619494/#msg_619494
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:
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.]]>Maxim Frolov2010-03-29T13:52:20-00:00Re: Best practices in model-driven development using EMF
https://www.eclipse.org/forums/index.php/mv/msg/194600/619495/#msg_619495
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 Merks2010-03-29T14:17:59-00:00