<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jorge Manrubia &#187; Model Driven Engineering</title>
	<atom:link href="http://jorgemanrubia.net/category/mdsd/feed/" rel="self" type="application/rss+xml" />
	<link>http://jorgemanrubia.net</link>
	<description>Personal Page</description>
	<lastBuildDate>Sat, 26 Jun 2010 07:36:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>The role of models in Agile and Model Driven Development approaches</title>
		<link>http://jorgemanrubia.net/2009/04/05/the-role-of-models-in-agile-and-mde-development-approaches/</link>
		<comments>http://jorgemanrubia.net/2009/04/05/the-role-of-models-in-agile-and-mde-development-approaches/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 23:31:59 +0000</pubDate>
		<dc:creator>Jorge Manrubia</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Model Driven Engineering]]></category>

		<guid isPermaLink="false">http://jorgemanrubia.net/2009/04/05/the-role-of-models-in-agile-and-mde-development-approaches/</guid>
		<description><![CDATA[When I was at the university, I remember being very interested in the suggestion that building software was like building bridges, and that software should have blueprints as sophisticated as those needed to build a bridge. I remember to has been told that you will never find a book on &#8220;How to build bridges in [...]]]></description>
			<content:encoded><![CDATA[<p>When I was at the university, I remember being very interested in the suggestion that building software was like building bridges, and that software should have blueprints as sophisticated as those needed to build a bridge. I remember to has been told that you will never find a book on &#8220;How to build bridges in 7 days&#8221; but you will find the equivalent on &#8220;how to learn C++ in 7 days&#8221;.</p>

<p>Today, I&#8217;m not so convinced that this analogy is a good one. I can&#8217;t agree more with <a href="http://pragdave.blogs.pragprog.com/pragdave/2007/10/art-in-programm.html">this quote from Dave Thomas</a> (the <a href="http://www.artima.com/intv/gardenP.html">Pragmatic Programmers proposed a new analogy</a> that I&#8217;m pretty sure not everyone can digest):</p>

<blockquote>
  <p>Software development is neither. Nor is it art. It&#8217;s just software development. People who look for the &#8220;software is like xxx&#8221; analogies are missing the point. Software development is like software development. Let&#8217;s decide what works for us, and have fun while doing it</p>
</blockquote>

<p>If you are interested, <a href="http://martinfowler.com/articles/newMethodology.html#PredictiveVersusAdaptive">Martin Fowler explains the reasons why the building bridges analogy fails</a>. I think, there is a sentence in his article that summarizes the problem very well:</p>

<blockquote>
  <p>Can you get a design that is capable of turning the coding into a predictable construction activity? And if so, is cost of doing this sufficiently small to make this approach worthwhile?</p>
</blockquote>

<p>This question is, obviously, rhetorical. You won&#8217;t. Traditionally, the gap between models and code has been huge. If you ignore this gap, then you may think that you have to make great efforts in creating very rich models, so the low-skilled and no-talented programmer can translate them into working code. And if you can create these models, then nothing stops you from planning the full development process up-front. Since the construction phase is mechanical and predictable, then you only have to calculate how much time you will have to spend in modeling. And since modeling is about drawing (if we use this development approach we are using UML for modeling everything for sure), this estimation should be easy too. After all, drawings, like Word documents or Power Point slides, always compile and work. Of course, this scenery would mean that <a href="http://www.cioupdate.com/insights/article.php/3801091/Why-Software-Development-Projects-Fail-Part-I.htm">software projects are delivered on time</a>, that the waterfall approach works, and that no matter wether the developers are talented or not.</p>

<p>In my opinion, the fact that models can&#8217;t be converted into code easily is addressed by the two development approaches I am more interested in:</p>

<ul>
<li><p>Agile development</p></li>
<li><p>Model Driven Engineering (<acronym title="Model Driven Engineering">MDE</acronym>)</p></li>
</ul>

<p>Although both approaches are perfectly compatible, they propose different ways when it comes to use models. Both approaches see models as a communication tool, as a resource that let us, as humans, reason and elaborate solutions that solve complex problems. While agile practitioners warns you against using models for anything more than this, <acronym title="Model Driven Engineering">MDE</acronym> practitioners propose to take the next step and convert models into first-class development artifacts.</p>

<p>The two approaches give different answers to the question of being able to create designs that can turn the coding into a predictable activity:</p>

<ul>
<li><p>Agile developers&#8217; answer is &#8220;no&#8221;. In fact, they propose to use many good development practices and exhaustive testing as a shield against problems when coding. Coding is not an ugly phase, neither is cleanly separated from design. There are not designers and programmers, there are developers. They will use models as a way to collaboratively obtain the best designs that solve the problem, not as a way of documenting it. And since they assume they can&#8217;t predict how the full process is going to be in earlier stages with detail, they are going to estimate and develop the project iteratively, using an empirical estimating approach.</p></li>
<li><p>The <acronym title="Model Driven Engineering">MDE</acronym> answer is a little bit more complex to say, since the paradigm is in its earlier stages. But if we manage to have <acronym title="Model Driven Engineering">MDE</acronym> solutions where we can define the best DSLs to describe a problem, and to specify how this input is translated into a working application, then, if these DSLs are defined in a way that are reusable in different instances of the same problem, we would be very close to being able to answer &#8220;yes&#8221; to that question.</p></li>
</ul>

<p>By the way, a confluence of both approaches can be seen in the BDD (Behavioral Driven Development) frameworks: such as <a href="http://rspec.info/">RSpec</a>, <a href="http://www.concordion.org/">Concordion</a> or <a href="http://cukes.info/">Cucumber</a>, but I think that topic deserves a post on its own.</p>]]></content:encoded>
			<wfw:commentRss>http://jorgemanrubia.net/2009/04/05/the-role-of-models-in-agile-and-mde-development-approaches/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Errors in my post on Comparing EMF Models</title>
		<link>http://jorgemanrubia.net/2008/11/19/errors-in-my-post-on-comparing-emf-models/</link>
		<comments>http://jorgemanrubia.net/2008/11/19/errors-in-my-post-on-comparing-emf-models/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 01:01:26 +0000</pubDate>
		<dc:creator>Jorge Manrubia</dc:creator>
				<category><![CDATA[Model Driven Engineering]]></category>

		<guid isPermaLink="false">http://jorgemanrubia.net/blog/?p=55</guid>
		<description><![CDATA[There was an error in the code originally posted in my article on Comparing EMF models. Thank you so much to Jim Showalter for warning me. The post has been updated with the right code. Now it&#8217;s also included an Eclipse sample project that compares two UML models.]]></description>
			<content:encoded><![CDATA[<p>There was an error in the code originally posted in my article on <a href="http://jorgemanrubia.net/blog/2008/07/06/comparing-emf-models/">Comparing EMF models</a>. Thank you so much to Jim Showalter for warning me. The post has been updated with the right code. Now it&#8217;s also included an <a href="http://jorgemanrubia.net/blog/wp-content/uploads/2008/07/emfcomparator-equalityhelper-eclipsesampleproject.zip">Eclipse sample project</a> that compares two UML models.</p>]]></content:encoded>
			<wfw:commentRss>http://jorgemanrubia.net/2008/11/19/errors-in-my-post-on-comparing-emf-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comparing EMF Models</title>
		<link>http://jorgemanrubia.net/2008/07/06/comparing-emf-models/</link>
		<comments>http://jorgemanrubia.net/2008/07/06/comparing-emf-models/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 16:37:26 +0000</pubDate>
		<dc:creator>Jorge Manrubia</dc:creator>
				<category><![CDATA[Model Driven Engineering]]></category>

		<guid isPermaLink="false">http://jorgemanrubia.net/blog/?p=30</guid>
		<description><![CDATA[At work, we needed a mechanism to compare EMF models. We are developing a system that uses ATL model to model transformations. We wanted to validate the transformations with JUnit unit tests. We needed a mechanism that let us compare expected models with transformed output models. EMF Compare I started evaluating the EMF Compare Framework. [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we needed a mechanism to compare <acronym title="Eclipse Modeling Framework">EMF</acronym> models. We are developing a system that uses <a href="http://www.eclipse.org/m2m/atl/"><acronym title="Atlas Transformation Language">ATL</acronym> model to model transformations</a>. We wanted to validate the transformations with JUnit unit tests. We needed a mechanism that let us compare expected models with transformed output models.</p>

<h3>EMF Compare</h3>

<p>I started evaluating the <a href="http://www.eclipse.org/modeling/emft/?project=compare#compare">EMF Compare Framework</a>. This framework targets model comparison by building a EMF model of the differences found during the comparison process. It let you evaluate differences pretty exhaustively. It evaluates source and target models by trying to match parallel elements. For related elements, matching is applied recursively.</p>

<p>The differences model is build of matched and unmatched elements. Matched elements let you examine the similarity of the matching (a number between 0 and 1). It seems as if two elements match just by having the same metaclass. Then, the similarity is set depending of how similar are their attributes. If the two models are identical, the root elements matching similarity is 1. If you change the value of two attributes, for example, then this precision was over 0.9. If you just change the order of two nodes, the precision was again under 1, even when the references in the metamodel weres unordered. This behavior wasn&#8217;t very good for our purposes, since models under comparison could have different orders  in their references.</p>

<p>If you think in the semantic of the comparison, two models can be identical when their unordered references don&#8217;t have the same order, don&#8217;t they? I suspect that EMF Compare probably would let you configure different comparison strategies easily, but we found a simpler way to achieve what we wanted.</p>

<h3>Modifying the <code>EcoreUtil.EqualityHelper</code> class to ignore order in references</h3>

<p>A friend told me have a look at the <code>equals()</code> method provided by the <code>org.eclipse.emf.ecore.util.EcoreUtil</code> class. It receives two <code>EObject</code> elements and compare them recursively. The two models have to had exactly the same structure in order be equal (no matter wether references were ordered or unordered). Again stabbed with the same problem. A look at the source of the method revealed that it delegates completely the functionality in a helper inner class: <code>EqualityHelper</code>. This class code is well factorized and it can be understood easily. The comparison of two list of elements was properly contained in an <code>equals(List, List)</code> method. So we try to hack this method in order to ignore orders when comparing.</p>

<p>After spending some hours trying to make a very complex modification of the method, another friend proposed the simplest way to compare two lists: sort them both and then compare sorted lists expecting exactly the same order. The solution was as obvious as wonderfully easy to implement: we already had the exhaustive comparison so we only needed to center our efforts in sorting the lists.</p>

<p>The last thing we needed was to find an <code>EObject</code> comparison criteria in order to implement the proper <code>java.util.Comparator</code>. This wasn&#8217;t that easy and we finally ended up parsing the <code>toString()</code> method result so we can obtain the attributes list string (the attribute&#8217;s name is hard coded in the EMF generated code of each concrete <code>toString()</code> method).</p>

<p>Below the <a href="http://jorgemanrubia.net/blog/wp-content/uploads/2008/07/emfcomparator.java">source code of the modified <code>EqualityHelper</code></a> is shown.</p>

<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EMFComparator <span style="color: #000000; font-weight: bold;">extends</span> EcoreUtil.<span style="color: #006633;">EqualityHelper</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">class</span> EObjectComparator <span style="color: #000000; font-weight: bold;">implements</span> Comparator<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> compare<span style="color: #009900;">&#40;</span>EObject object1, EObject object2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> targetString1 <span style="color: #339933;">=</span> extractComparisonString<span style="color: #009900;">&#40;</span>object1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> targetString2 <span style="color: #339933;">=</span> extractComparisonString<span style="color: #009900;">&#40;</span>object2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> targetString1.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>targetString2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> extractComparisonString<span style="color: #009900;">&#40;</span>EObject object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> object.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">toHexString</span><span style="color: #009900;">&#40;</span>object.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; @Override<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> equals<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">List</span></a> list1, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">List</span></a> list2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acomparator+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Comparator</span></a> comparator <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> EObjectComparator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span> sortedList1 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>list1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span> sortedList2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>EObject<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>list2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acollections+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Collections</span></a>.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span>sortedList1, comparator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acollections+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Collections</span></a>.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span>sortedList2, comparator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>sortedList1, sortedList2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span></div></div>

<h3>Conclusion</h3>

<p>I was a bit surprised of not finding this problem solved when googling for it. I&#8217;m sure more people have had this need and have solved this problem before. When you are transforming models, you need a formal way to compare real output models and expected output models. I wouldn&#8217;t develop a complex transformation system with a lot of transformation rules without this system. Lateral effects when modifying transformation rules can break the system and being easily unnoticed. If transformations are an essential mechanism in a data loading system, like our case is, this danger is not acceptable.</p>

<h3>Update (2008-11-19)</h3>

<p>There was an error in the code originally posted. The method <code>extractComparisonString()</code> received an <code>String</code> object, when it should receive an  <code>EObject</code> (it didn&#8217;t make sense). Thank you so much to Jim Showalter for warning me. I should have copy/pasted from what I coded at work, instead of rewriting at home.</p>

<p>You can also download an <a href="http://jorgemanrubia.net/blog/wp-content/uploads/2008/07/emfcomparator-equalityhelper-eclipsesampleproject.zip">Eclipse sample project</a> that compares two UML models. It includes the source of the comparator.</p>]]></content:encoded>
			<wfw:commentRss>http://jorgemanrubia.net/2008/07/06/comparing-emf-models/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
