About

hallo

Archives

01 Feb - 28 Feb 2009
01 Apr - 30 Apr 2009
01 Jun - 30 Jun 2009
01 Jul - 31 Jul 2009
01 Aug - 31 Aug 2009
01 Oct - 31 Oct 2009
01 Nov - 30 Nov 2009
01 Jan - 31 Jan 2010
01 Mar - 31 Mar 2010
01 Jul - 31 Jul 2010
01 Oct - 31 Oct 2010
01 Nov - 30 Nov 2010
01 Jun - 30 Jun 2011
01 Nov - 30 Nov 2011

Links

Dawn

Search!

Last Comments

Polo Outlet (Slides for the Da…): Very good, very good. Let…
Polo Outlet (It's demo time): Very good, very good. Let…
Coach Outlet Stor… (Slides for the Da…): why it really is viewed a…
Coach Outlet Stor… (It's demo time): why it really is viewed a…
Burberry Outlet O… (Slides for the Da…): Hi, this is my first visi…
Burberry Outlet O… (It's demo time): Hi, this is my first visi…
Burberry Outlet O… (Distributed Ecore…): Hi, this is my first visi…
Coach Outlet Stor… (Distributed Ecore…): why it really is viewed a…
Polo Outlet (Distributed Ecore…): Very good, very good. Let…
qifei2012 (Slides for the Da…): labeled colours significa…

Stuff

Powered by Pivot - 1.40.6: 'Dreadwind' 
XML: RSS Feed 
XML: Atom Feed 

« Some Sundays are diff… | Home | This is my legacy ...… »

EMF rocks!

23 03 10 - 13:37 Well, this is a statement the most of you are certainly aware of. But there might be some out there who have not already been assimilated or who have never ever heard of model driven software development at all. For those and certainly for all others I'll give some thought about one of my latest EMF experiences.

But let me start at the beginning. I believe that it is quite a good idea to have a playground, an abstract idea or project, where you can try out new technologies. If you implement this idea with different technologies this gives you a good overview about the advantages and drawbacks of the different approaches. Well, my playground is called the "Moviebase". Long, long time ago when I made my apprenticeship I learned a bit about web servers, PHP and databases and so I came up with the idea to develop a small application to manage my movies.
O.k. the desing was not perfect but actually stable enough to work for several years. Later in university I learned a lot about fancy new technologies like servlet containers, web services, AJAX, RSS, Hibernate (at this time they were new) and all the other interesting technologies which let the buzzword catalogue grow bigger and bigger. So I decided to re-implement the Moviebase using the new stuff.



Well, this is also some years ago, but I remember having some trouble with the following scenario:
A movie has actors. So far so good. That's actually true for most movies - except documentations. But to be honest, documentations are not the majority in my movie catalogue. Because I haven't heard about modelling or EMF at all I started coding this specific classes and lists for it by hand. I quick typing action and I was able to get all actors from the movie. But movies have directors, too. O.k. this brought up the base class Person and it's subclasses Actor and Director. Added getter and setter and it was done. Hmmm, who wrote the sound track could be interesting, too (especially if you intent to write a MusicBase and combine it with the MovieBase). So again some typing actions brought the needed code.



That's enough for the model. And now it is time were the trouble starts. Getting/setting actors and so on is nice. But what if you would like to see all persons involved in a movie? O.k. writing a method called "getPersons" would do the trick - if you take care that the persons are not doubled - some actors are also playing director or compose the music for the movie. And deleting a person is even worst. But that is not the real problem. For now we took to a look at movies. But what about the Person object? Don't you want to know in which movies he played or where she was director? Or maybe you want to retrieve every movie the person was involved? Writing this and taking care for the integrity of all lists could be quite troublesome.



But to cut the long story short, all these problems are easily solved with EMF. To be exact - with FeatureMaps. To be honest I never liked FeatureMaps before I used them. ;)
But you can easily model the above mentioned scenario Just create an attribute with type FeatureMapEntry in your movie called "persons". Then add actors, directors and composers as may-valued references and combine them using the EAnnotations described in the EMF book. Do the same for the persons and let them point the the specific opposite in the movie. E.g. Person.moviesAsActors point to the actors feature in the movie. That's it. Now you have bidirectional FeatureMaps. Just generate the code and EMF will care for the rest. You can add movies to actors or directors to movies and the whole synchronisation will be done by EMF - groovy. Just see the snippet below for an examples


Person person = MediabaseFactory.eINSTANCE.createPerson();
Movie movie = MediabaseFactory.eINSTANCE.createMovie();

movie.getActors().add(person);
movie.getDirectors().add(person);

System.out.println("persons:" + movie.getPersons().size()); //prints 2

System.out.println("actors:" + movie.getActors().size());//prints 1
System.out.println("directors:" + movie.getDirectors().size());//prints 1
System.out.println("composers:" + movie.getComposers().size());//prints 0

System.out.println("MyMovies: " + person.getMovies().size());//prints 2
System.out.println("MyMovies as actor: " + person.getMoviesAsActor().size());//prints 1
System.out.println("MyMovies as director : " + person.getMoviesAsDirector().size());//prints 1
System.out.println("MyMovies as composer: " + person.getMoviesAsComposer().size());//prints 1


And that is not only reliable and stable but can also be modelled quite fast. If you know what to do you can define this model in just a few minutes. Not yet convinced using EMF? Try it out and I guess you will ;)
This was a small insight into the advantages EMF offers. Unfortunately my time is limited at the moment, so the MovieBase development slowed down. But I already had some time to play with EMF Databinding - and hey - it rocks too ;)

So, wherever you are - Have fun and enjoy the springtime. :)
two comments

Hi Martin,

Nice blog, nice pictures, give us more! ;-)
Eike Stepper (URL) - 23 03 10 - 14:34

Heya..thanks for the post and great tips..even I also think that hard work is the most important aspect of getting success.
Acai Berry () (URL) - 26 03 10 - 19:07


Trackback link:

Please enable javascript to generate a trackback url

 

Linkdump