DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

10 common EMF mistakes

Nirmal Sasidharan user avatar by
Nirmal Sasidharan
·
Jun. 10, 11 · Interview
Like (0)
Save
Tweet
Share
10.22K Views

Join the DZone community and get the full member experience.

Join For Free

1. treating emf generated code as only an initial code base

initial_code emf is a good startup kit for introducing mdsd (model-driven software development) in your project. anyone who has been introduced to emf and had their first code generated using emf will for sure be impressed by the short turn around time needed to have an initial version of your model based application up and running. for many, the thrill ends as soon as you need to change the behaviour of generated code and have to dig into it and understand it. it is complex, but only complex as any other similar sized framework. many projects i have come across make a mistake at this point. they start treating the emf generated code as an initial code base and start making it dirty by modifying it by hand. adding @generated not tags in the beginning and not anymore later. at this point you part ways with “emf way of doing things” and also with mdsd.

the customizations mostly start with the generated editor. this is quite acceptable as the editor is intended as an initial “template” and it expects you to customize it. however, this is not the case with model and edit projects. they have to be in sync with your model and this needs making some strong decisions, specifically –  ”i will not touch the generated code”. follow emf recommended way of changing generated code or use dependency injection .

2. model modification without emf commands

emf_model_modification

in emf you deal a lot with model objects. almost any ui selection operation hands over a model object to you. it is so easy to fall into the trap of changing the state of the model objects directly once you have access to it, either using the generated model api or using reflective methods. problems due to such model updates are detected only later, mostly when undo/redo operations stops working as expected.

use emf commands! modify your model objects only using commands. either directly using emf commands, extending them or creating your own commands. when you need to club many operations as a single command use compoundcommand s. use changecommand when you are up to making a lot of model changes in a transactional way.

3. not reacting to notifications/overuse of notifications

notification emf notification is one the most powerful features of the framework. any change to model objects are notified to anyone who is interested in knowing about it. many projects decide to ignore listening to model changes and react to model changes by traversing the model again to look for changes or making assumptions about model changes and combining the behaviour into ui code.

when you want to react to a model change, don’t assume that you are the only one going to originate that change. always listen to model changes and react accordingly. don’t forget the handy econtentadapter class.

on the contrary, some projects add a lot of listeners to listen to model changes without applying proper filters. this could greatly slow down your application.

4. forgetting ecoreutils

ecoreutil

before writing your own utility functions, keep an eye on ecoreutils class. mostly, the generic function you are trying to implement is already there.






5. leaving namespace uri as default

id when you create an ecore model, emf generates a default prefix and namespace uri for you. mostly this is left as it is without realizing that this is the most important id for your new model. only when newer versions of the model needs to be released later, people start looking out for meaningful uris.

change the default to a descriptive one before generating code. for example, including some version information of the model.


6. ui getting out of sync with model

binding the emf generated editor makes use of jface viewers. these viewers are always kept in sync using the generated itemproviders. however these viewers cannot always satisfy the different ui requirements. you might have to use other swt components or eclipse forms. at this juncture, many implementors mix ui and model concerns together and in turn lose the sync between the model and ui.

although, you could go ahead and implement your custom viewers, the easier way would be to use emf databinding .

7. relying on default identification mechanism

reference every emf object is identified by a xpath like uri fragment.  for example, //@orders.1/@items. 3. this is the default referencing mechanism within an emf model or across models. if you look closely you could see that the default mechanism is based on feature names and indexes. the default implementation could turn dangerous if the index order changes and the references are not updated accordingly.

extend this to uniquely identify your model object or simply assign an intrinsic id to your model object. emf will then use these ids to reference your objects.

8. forgetting reflective behavior

emf_reflection many consider the reflective features of emf as an advanced topic. it is not as complex as it seems.

instead of depending fully on generated apis, think about creating generic reusable functions which makes use of the meta information every eobject carries. have a look at the implementation of ecoreutil.copy function to understand what i mean.

9. standalone? why do i bother

standalone a misunderstanding most people have is that emf is eclipse specific. emf can well run outside eclipse as “stand-alone” applications.

while developing applications based on emf you should design your applications such that the core is not tied to eclipse. this would allow your applications to be run even in a non osgi server-side environment.

10. not reading the emf bible

emf_bible
this is the biggest mistake a new comer could make. the book is a must read for anyone who starts working with emf.

order now (hope this fetches me a beer at the next eclipsecon europe ;))

from http://nirmalsasidharan.wordpress.com/2011/05/25/10-common-emf-mistakes/

Eclipse Modeling Framework

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Comparing Map.of() and New HashMap() in Java
  • The Path From APIs to Containers
  • 5 Steps for Getting Started in Deep Learning
  • Top 10 Best Practices for Web Application Testing

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: