<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Valtech UK</title>
	
	<link>http://blog.valtech.co.uk</link>
	<description>Aggregated works of Valtech UK consultants</description>
	<lastBuildDate>Wed, 08 Sep 2010 15:29:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ValtechUK" /><feedburner:info uri="valtechuk" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Testing and concurrency</title>
		<link>http://feedproxy.google.com/~r/ValtechUK/~3/l02X604s_PE/</link>
		<comments>http://blog.valtech.co.uk/agile/testing-and-concurrency/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 15:29:42 +0000</pubDate>
		<dc:creator>Andrew Rendell</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.valtech.co.uk/?p=373</guid>
		<description><![CDATA[Our team is currently working with a client on a medium sized, medium complexity Java application which has quite low test coverage. We are introducing characterisation tests to snapshot functionality. These will give us the confidence to refactor away technical debt and extend the application without regression. One of the problems we are experiencing is [...]]]></description>
			<content:encoded><![CDATA[<p>Our team is currently working with a client on a medium sized, medium complexity Java application which has quite low test coverage. We are introducing <a href="http://en.wikipedia.org/wiki/Characterization_test">characterisation </a>tests to snapshot functionality. These will give us the confidence to refactor away technical debt and extend the application without regression. One of the problems we are experiencing is the concurrent nature of the application. I have have worked on applications in the past which supported very high concurrency without issue but this application is different. I have not fully thought through why this application does differ but there are some obvious points:</p>
<ul>
<li>This application spawns      threads in Java code a lot. In previous applications we have always      avoided this complexity by utilising somebody else&#8217;s thread pool code.</li>
<li>I am used to stateless      service classes which operate on domain objects. The stateless service      classes obviously have no concurrency issues and the domain objects can be      protected using synchronisation blocks. This application seems to have a      lot more stateful objects that interact (this is anecdotal, I am have not      analysed the code specifically for this attribute).</li>
</ul>
<p>One of the first refactorings we are looking at is to remove all the Thread.sleep calls from test classes. The CI server reports significant number of test failures which turn out to be false positives. In a significant number of cases the use of Thread.sleep is to blame. I have seen two slightly different uses of Thread.sleep in the test code.</p>
<ol>
<li>The test spawns a thread      which is calling some method of the class under test whilst the main test      thread interacts with the class under test in some other way. The test      thread calls Thread.sleep to ensure that the second thread has time to      complete its processing before the test verifies the post conditions.</li>
<li>The class under test      contains some internal thread spawning code. The test thread again needs      to execute a Thread.sleep to remove the chances of a race condition before      firing the asserts.</li>
</ol>
<p>Both these approaches suffer from the same problems.</p>
<ul>
<li>The Thread.sleep might be      long enough to allow the second thread to complete processing on one      machine (e.g. the developers high spec workstation) but it is not long      enough to allow the thread to complete its processing on a heavily loaded,      differently configured, usually more resource constrained CI server. Under      certain load situations the test fails. It works in others. The use of      Thread.sleep has made the test non-deterministic.</li>
<li>Often the response to the      above problem is to make the sleep longer. Yesterday I saw a very simple      test which took over thirteen seconds to execute. Most of that test      duration was sleeps. Refactoring to remove the sleeps resulted in a test      that executed in 0.4 seconds. Still a slowish test but a vast improvement.      The last application I worked on had 70% coverage with 2200 tests. If each      one had taken thirteen seconds to execute then a test run would have taken      almost eight hours. In reality that suite took just over a minute on my      workstation to complete. You can legitimately ask a developer to run a      test suite which takes one minute before every checkin and repeat that      execution on the CI server after checkin. The same is not true of a test      suite that takes eight hours. You are probably severely impacting the      teams velocity and working practices if the build before checkin takes      eight minutes. There are very few excuses for tests with arbitrary delays      built into them.</li>
</ul>
<p>To resolve both issues we introduce a <a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CountDownLatch.html">count down latch</a>.</p>
<p>Where the test spawns a thread, the latch is decremented inside the spawned thread and where the test code had a sleep a latch.await(timeout) is used. We always specify a timeout to prevent a test that hangs in some odd situation. The timeout can be very generous, e.g. ten seconds where before a one second sleep was used. The latch will only wait until the work is done in the other thread and the race condition has passed. On your high spec workstation it might well not wait at all. On the overloaded CI server it will take longer, but only as long as it needs. A truly massive delay is probably not a great idea as there is a point where you want the test to fail to indicate there is a serious resource issue somewhere.</p>
<p>Where the class under test spawns a thread (an anti-pattern I suspect) then we amend the code so it creates a latch which it then returns to callers. The only user of this latch is the test code. Intrusive as it is, it is often the only way to safely test the code without more significant refactoring.</p>
<p>There are some larger issues here. Is the code fundamentally wrong in its use of threading? Should it be recoded to use a more consistent and simple concurrency model and rely more on third party thread pool support?</p>
<p>At risk of straying from my comfort zone of simple, pragmatic, software delivery, deep down I have never been very happy about the implications of complicated multi-threaded code and automated testing. You can write a class augmented with a simple and straightforward test class which verifies the classes operation and illustrates its use. You can apply coverage tools such as Emma and Cobutura which can give a measure of the amount of code under test and even the amount of complexity that is not being tested. I am not convinced it is always possible to write simple tests that &#8216;prove&#8217; that a class works as expected when multiple threads are involved (note I say always and simple).</p>
<p>I do not know of any tools that can give you an assurance that you code will always work no matter what threads are involved. Perhaps a paradigm shift such as that introduced by languages such as Scala and Erlang will remove this issue?</p>
<p>There is some good advice available regarding <a href="http://www.theserverside.com/news/1365191/Testing-Concurrent-Programs">testing concurrent code</a> and I am sure lots of very clever people have spent lots of time thinking this through but its certainly not straight in my head yet.</p>
<p>﻿</p>
<img src="http://feeds.feedburner.com/~r/ValtechUK/~4/l02X604s_PE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.valtech.co.uk/agile/testing-and-concurrency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.valtech.co.uk/agile/testing-and-concurrency/</feedburner:origLink></item>
		<item>
		<title>Agile Business Analysis at Agile2010</title>
		<link>http://feedproxy.google.com/~r/ValtechUK/~3/EPx55LQQkz0/</link>
		<comments>http://blog.valtech.co.uk/agile-requirements/agile-business-analysis-at-agile2010/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 12:59:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile Requirements]]></category>

		<guid isPermaLink="false">http://blog.valtech.co.uk/agile-requirements/agile-business-analysis-at-agile2010/</guid>
		<description><![CDATA[The slides for this session are now available for download   On Thursday Gary Jones will be talking about Agile Business Analysis techniques in E-3 at 13:30. This post brings together some of the resources he will be referring to and other related references. If you have a favourite resource for other BA techniques please [...]]]></description>
			<content:encoded><![CDATA[<p><em>The slides for this session are now available for download <a href="http://blog.valtech.co.uk/wp-content/plugins/download-monitor/download.php?id=1">Agile Business Analysis - Agile 2010</a></em></p>
<p> </p>
<p>On Thursday Gary Jones will be talking about Agile Business Analysis techniques in E-3 at 13:30.</p>
<p>This post brings together some of the resources he will be referring to and other related references. If you have a favourite resource for other BA techniques please feel free to comment below.<br /> <strong><a title="Jeff Patton on Pragmatic Personas" href="http://www.infoq.com/presentations/pragmatic-personas" target="_blank">Jeff Patton on Pragmatic Personas</a></strong><strong><br /> </strong>This presentation from last years conference is a great place to start to find out more about identifying those differences in customer need that really make a difference to your product.</p>
<p><strong><a title="Rob Thomset - Radical Project Management" href="http://www.amazon.com/exec/obidos/ASIN/0130094862/qid=1020680019/ref=sr_11_0_1/103-9406863-6535856" target="_blank">Rob Thomset &#8211; Radical Project Management</a></strong><strong><br /> </strong>This book is where we discovered the sliders technique which provides a framework for considering relative priorities of non-functional aspects of the system.</p>
<p><strong><a title="Software by Numbers" href="http://www.amazon.co.uk/Software-Numbers-Low-Risk-High-Return-Development/dp/0131407287/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1281444597&amp;sr=8-1" target="_blank">Software by Numbers by Mark Denne and Jane Cleland-Huang </a></strong><br /> This was the book that introduced the notion of Minimal Marketable Features. This technique provides a means to realise the promise of incremental delivery of customer valued software.</p>
<p><strong><a title="Crossing the Chasm" href="http://www.amazon.com/exec/obidos/ASIN/0066620023/cutterinformatco" target="_blank">Geoffrey Moore&#8217;s book Crossing the Chasm</a></strong><br /> This book describes the simple visioning exercise we use that, it turns out, provides the rails for the project helping us identify where we are going off track or experiencing a change in strategy.</p>
<p>Others we like include:</p>
<p><strong><a title="9 Box interview technique&lt;br &gt;&lt;/a&gt;" href="http://dnicolet1.tripod.com/agile/index.blog/1765142/nine-boxes/" target="_blank">9 Box interview technique<br /> </a></strong>Dave Nicolette describes this technique from Keith Eades&#8217;s book, <a title="Solution Selling" href="http://www.amazon.com/New-Solution-Selling-Revolutionary-Changing/dp/0071435395" target="_blank">Solution Selling</a>.</p>
<p><!-- technorati tags start --></p>
<p style="text-align:right;font-size:10px;">Technorati Tags: <a rel="tag" href="http://www.technorati.com/tag/Agile Requirements">Agile Requirements</a>, <a rel="tag" href="http://www.technorati.com/tag/Business Analysis">Business Analysis</a></p>
<p><!-- technorati tags end --></p>
<img src="http://feeds.feedburner.com/~r/ValtechUK/~4/EPx55LQQkz0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.valtech.co.uk/agile-requirements/agile-business-analysis-at-agile2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.valtech.co.uk/agile-requirements/agile-business-analysis-at-agile2010/</feedburner:origLink></item>
		<item>
		<title>Enterprise EPiServer: Form vs Structure</title>
		<link>http://feedproxy.google.com/~r/ValtechUK/~3/fhkWDT3oeNE/</link>
		<comments>http://blog.valtech.co.uk/uncategorized/enterprise-episerver-form-vs-structure/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 17:27:24 +0000</pubDate>
		<dc:creator>johan</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Digital Strategy]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.valtech.co.uk/?p=325</guid>
		<description><![CDATA[This post was originally posted here by Martin Ottosen. A common motivation for doing enterprise CMS solutions is the always elusive goal of building a platform (structure) which allows the organization to quickly and cheaply create new websites by leveraging the initial investment of the platform. The vision however gets tainted quickly as reality sets [...]]]></description>
			<content:encoded><![CDATA[<div>
<p><em>This post was originally posted <a title="Martin Ottosen - EPiServer form vs. structure - Valtech DK" href="http://blog.valtech.dk/2010/06/enterprise-episerver-form-vs-structure/">here</a> by Martin Ottosen.</em></p>
<p>A common motivation for doing enterprise CMS solutions is the always elusive goal of building a platform (structure) which allows the organization to quickly and cheaply create new websites by leveraging the initial investment of the platform. The vision however gets tainted quickly as reality sets in. The various  business units / brand owners / product managers usually have very different ideas about how they need to communicate to the outside world, they have different ideas about the form that suits their needs. So quickly you end up in a sticky situation where you have to choose between doing a lot of new development work everytime a new site is added to the platform, or restrict the flexibility of the platform to keep it financially feasible.</p>
<h2 id="mf23">Form over structure</h2>
<p>In other words, one important goal in enterprise CMS is to create a <strong>structure </strong>which is shared and cost-effective while allowing for a high degree of flexibility in the <strong>form </strong>of the different sites based on that structure. Lets consider an example problem: We are implementing a generic brand website which is to be the first (of many) sites based on a shared enterprise platform financed by the centralized IT department. Upon inspection of the detailed requirements (wire frames, use cases, information architecture, etc.) the developers are able to determine:</p>
<ol>
<li>What page types we need to support the requirements (in other words what data is required to render e.g. the front page)</li>
<li>What templates are required to adhere to the specified layout (by transforming the data from e.g. the front page page type to html)</li>
<li>How the different page types are structured (e.g. what type of page can be created as a child of front page)</li>
</ol>
<p>There… a nice tight data model with a layout on top. Requirements have been met, jobs done… and along comes the next brand site. And it turns out they have different ideas about how they need to communicate, to the outside world. They need a different form, but we have created a very rigid structure, so we need more page types and templates to satisfy their requirements. Slowly we add more and more templates to support the requirements of new sites, driving up costs, increasing complexity (for both editors and developers) and lowering time-to-market. What to do?</p>
</div>
<div>
<h2 id="mf33">Reducing structural granularity</h2>
<p><img class="alignleft" src="http://blog.valtech.dk/wp-content/uploads/2010/06/Composer1-137x300.jpg" alt="EPiServer Composer Page Structure" width="137" height="300" />Here is one strategy we employ using Composer: In case you are not familiar with it, <a id="mfa12" title="Composer" href="http://www.episerver.com/en/Products/EPiServer-Composer/" target="_blank">Composer</a> is an add-on to <a id="mfa13" href="http://www.episerver.com/en/Products/EPiServer-CMS-6/">EPiServer CMS</a> which is essentially yet another implementation of drag and drop interface components (similar to webparts, portlets, etc.). Despite it’s apparent simplicity however, I think it has profound consequences for what you can do with EPiServer, particularly in an enterprise setup. Our approach is simple:</p>
<ol>
<li>Every page on the website (and by page I mean something that the end-user can find on google) is just… a page. So just one template!</li>
<li>Every page has just one content place holder in the full width of the master layout</li>
<li>Into that place holder layout rows can be added</li>
<li>Into the layout rows, content blocks can be added</li>
</ol>
<p>We have dispensed with the notion of typed pages altogether. A page is just a structural unit which has only the necessary information for a page to work (a location in the site tree, a URL, access control settings, etc.). The <strong>form</strong> of the individual pages can be composed and changed with a very high degree of freedom by the editor with no development effort required. The templates that were previously managed by developers are replaced by composer templates, which the editors can manage themselves.</p>
<p>Using this strategy, we get a lot more opportunities for reuse across otherwise very diverse websites, time-to-market and TCO is greatly reduced, while quality is improved from having less code to manage. This is of course just one piece of the puzzle, but to me an important initial design decision which has a lot of impact.</p>
</div>
<img src="http://feeds.feedburner.com/~r/ValtechUK/~4/fhkWDT3oeNE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.valtech.co.uk/uncategorized/enterprise-episerver-form-vs-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.valtech.co.uk/uncategorized/enterprise-episerver-form-vs-structure/</feedburner:origLink></item>
		<item>
		<title>Unit tests, code coverage and the hidden trap…</title>
		<link>http://feedproxy.google.com/~r/ValtechUK/~3/YzJ8cgUO5cw/</link>
		<comments>http://blog.valtech.co.uk/uncategorized/unit-tests-code-coverage-and-the-hidden-trap/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 14:49:30 +0000</pubDate>
		<dc:creator>Jorge Migueis</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coverage]]></category>
		<category><![CDATA[Unit test]]></category>

		<guid isPermaLink="false">http://blog.valtech.co.uk/?p=330</guid>
		<description><![CDATA[Quality has always been a &#8220;hot&#8221; subject in software engineering, and several good development practices used in Agile development, unit testing for example, have been created to improve the quality of the softwares developed. Programme Managers, Project Managers and Assurance Quality Managers haven&#8217;t just been looking for techniques to improve quality, they&#8217;ve also been looking [...]]]></description>
			<content:encoded><![CDATA[<p>Quality has always been a &#8220;hot&#8221; subject in software engineering, and several good development practices used in Agile development, unit testing for example, have been created to improve the quality of the softwares developed.</p>
<p>Programme Managers, Project Managers and Assurance Quality Managers haven&#8217;t just been looking for techniques to improve quality, they&#8217;ve also been looking for ways to monitor the quality of the projects and the application of these techniques.</p>
<p>This has lead to the development of numerous tools to check the unit testing coverage, the style of the code and its compliance to well accepted rules. Plus, of course, dashboards that gather all that information and present it in a user friendly way.</p>
<p>One of the most commonly used metrics is the code coverage of the unit tests. We often see in Agile teams rules like, &#8220;the line coverage should at least 80%&#8221;, or &#8220;the branch coverage should be at least 70%&#8221;. But&#8230;herein lies the hidden trap.<span id="more-330"></span><!--more-->The code coverage is not enough to verify the quality of the tests. Recently, I saw some unit tests that were exercising the code, but did not have real assertions. The test would only check that the data received was not nil. Something like:</p>
<p><code style="color: coral; text-align: left;"><br />
/**<br />
* Example of a useless test.<br />
* As Mashooq Badar explained in a previous entry<br />
* of this blog, tests should have explicit names.<br />
*/<br />
public void<br />
testThatTheCodeRunsWithoutCheckingTheReturnedValue() {<br />
// Prepare Context<br />
// create mock object for instance using Mockito<br />
AnInterfaceToMock mockObject =<br />
mock(AnInterfaceToMock.class);<br />
// Create instance of class under test<br />
// and inject mock objects<br />
ClassUnderTest anInstance = new ClassUnderTest();<br />
anInstance.setInterfaceToMock(mockObject);<br />
// Run code to test<br />
List result = anInstance.operationUnderTest();<br />
// Assertions<br />
assertNotNull(result);<br />
}</code></p>
<p>This test is almost useless, as it does not check the list of data it received. We do not know whether or not the &#8216;operationUnderTest&#8217; performed its job properly. The only thing this test shows is that the &#8216;operationUnderTest&#8217; did not throw up an exception. A change in the code of the class under test will probably not affect this test. However, the quality dashboard will present a healthy project with a high level of code coverage and instil a false confidence in the managers&#8217; minds. There is no tool that can perform that extra check, for now.</p>
<p>This is one of the reasons why code reviews have to be performed, published and monitored as well.</p>
<img src="http://feeds.feedburner.com/~r/ValtechUK/~4/YzJ8cgUO5cw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.valtech.co.uk/uncategorized/unit-tests-code-coverage-and-the-hidden-trap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.valtech.co.uk/uncategorized/unit-tests-code-coverage-and-the-hidden-trap/</feedburner:origLink></item>
		<item>
		<title>Project Estimates</title>
		<link>http://feedproxy.google.com/~r/ValtechUK/~3/vNkg671UkfQ/</link>
		<comments>http://blog.valtech.co.uk/agile/project-estimates/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 16:10:03 +0000</pubDate>
		<dc:creator>Mashooq Badar</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Development Process]]></category>
		<category><![CDATA[estimation]]></category>

		<guid isPermaLink="false">http://mashb.wordpress.com/?p=125</guid>
		<description><![CDATA[In my previous post on High Level Project Estimates, I talked about 3 points estimates to help provide an up-front estime of effort for a project. Aside from the effort estimate you also need to consider other aspects that the team will spend time on. The following are some aspects I consider with the kind [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mashb.wordpress.com&#38;blog=7354608&#38;post=125&#38;subd=mashb&#38;ref=&#38;feed=1" />]]></description>
			<content:encoded><![CDATA[<p>In my previous post on <a href="http://mashb.wordpress.com/2010/03/19/high-level-project-estimates/">High Level Project Estimates</a>, I talked about 3 points estimates to help provide an up-front estime of effort for a project. Aside from the effort estimate you also need to consider other aspects that the team will spend time on. The following are some aspects I consider with the kind of percentages (above the effort estimate) I have experienced. Note: these percentages are by no means standard or the norm they are essentially a rough guess based on the projects I have worked .</p> <ul> <li>Planning Meetings @ 10%</li> <li>Demos @ 2%</li> <li>Code Reviews @ 5%</li> <li>Retrospectives @ 5%</li> <li><a href="http://www.agilemanagement.net/index.php/blog/Embrace_Dark_Matter/">Dark Mater</a> @15%</li> <li>Bugs @15%</li> <li>New Technical Stories and Spikes @ 25%</li> <li>Change Requests (shouldn’t average more than 15%)</li> <li>Holidays and Sick Leave @ 5%</li> </ul> <p>You will also need to consider Management Overheads as well as Business Analysts (if included in the team), QA/Functional Testing, Support and Maintenance (if required).</p> <p><a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mashb.wordpress.com/125/"><img src="http://feeds.wordpress.com/1.0/comments/mashb.wordpress.com/125/" border="0" alt="" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mashb.wordpress.com/125/"><img src="http://feeds.wordpress.com/1.0/delicious/mashb.wordpress.com/125/" border="0" alt="" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mashb.wordpress.com/125/"><img src="http://feeds.wordpress.com/1.0/stumble/mashb.wordpress.com/125/" border="0" alt="" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mashb.wordpress.com/125/"><img src="http://feeds.wordpress.com/1.0/digg/mashb.wordpress.com/125/" border="0" alt="" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mashb.wordpress.com/125/"><img src="http://feeds.wordpress.com/1.0/reddit/mashb.wordpress.com/125/" border="0" alt="" /></a> <img src="http://stats.wordpress.com/b.gif?host=mashb.wordpress.com&amp;blog=7354608&amp;post=125&amp;subd=mashb&amp;ref=&amp;feed=1" border="0" alt="" /></p><img src="http://feeds.feedburner.com/~r/ValtechUK/~4/vNkg671UkfQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.valtech.co.uk/agile/project-estimates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.valtech.co.uk/agile/project-estimates/</feedburner:origLink></item>
		<item>
		<title>One team, one language</title>
		<link>http://feedproxy.google.com/~r/ValtechUK/~3/jBiaNCMs_9k/</link>
		<comments>http://blog.valtech.co.uk/development/one-team-one-language/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 11:52:00 +0000</pubDate>
		<dc:creator>Sandro Mancuso</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ubiquitous Language]]></category>

		<guid isPermaLink="false" />
		<description><![CDATA[On a previous post I was discussing, among other things, how code often doesn't represent the business properly. The code "satisfies" the business requirements but doesn't express them very well. The main reason for that is because we, developers, like...]]></description>
			<content:encoded><![CDATA[<p>On a <a href="http://craftedsw.blogspot.com/2010/06/wolf-in-sheeps-clothing.html">previous post</a> I was discussing, among other things, how code often doesn't represent the business properly. The code "satisfies" the business requirements but doesn't express them very well. The main reason for that is because we, developers, like to abstract business terms and rules into technical implementations and patterns.</p> <p>Very often, we discuss the user stories (requirement documents, use cases, whatever the methodology used is) with the "domain experts" and as soon as we understand what needs to be done, we map the requirements to a <a href="http://craftedsw.blogspot.com/2010/06/wolf-in-sheeps-clothing.html">technical design</a> (actions, services, entities, helpers, DAOs, etc) that is <a href="http://craftedsw.blogspot.com/2010/06/wolf-in-sheeps-clothing.html">completely meaningless</a> to the domain experts. Sometimes, even among developers themselves, different names and expressions are used to refer to the same thing. The main reason is that different developers talk to different domain experts and come up with different abstractions. As a result,  the usage of different terms to describe requirements leads to confusion, duplication of code and unpredictable behaviour in the system.</p> <p>The first step towards an expressive and domain-focused design is to have a common language among ALL members of the team. ALL means ALL: developers, domain experts (business analysts, users, product owner, etc), testers, project manager and anyone else involved in the project.<span id="more-308"></span></p> <p>Developers very often say that domain experts don't understand objects and database and because of that, they need to "translate" business requirements into software design. However, we developers don't understand the business as well as the domain experts do, what more often than not, leads to imperfect and confusing abstractions.</p> <p><strong>The Ubiquitous Language</strong></p> <blockquote><p><em>A language structured around the domain model and used by all team  members to connect all the activities of the team with the software.</em></p></blockquote> <p><a href="http://domaindrivendesign.org/node/132">The Ubiquitous Language</a> is one of the most important things, if not the most, in <a href="http://domaindrivendesign.org/">Domain-Driven Design</a>. The main idea is that the whole team speaks a single language, that is the business language.</p> <p> </p> <div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="http://4.bp.blogspot.com/_ONTWYUiOUvw/TBgVFwNWmdI/AAAAAAAAAJA/2ADOaIfW-fc/s1600/ubiquitouslanguage.jpg"><img src="http://4.bp.blogspot.com/_ONTWYUiOUvw/TBgVFwNWmdI/AAAAAAAAAJA/2ADOaIfW-fc/s400/ubiquitouslanguage.jpg" border="0" alt="" width="400" height="182" /> </a></div> <div class="separator" style="clear: both; text-align: left;">Business terms related to the software to be implemented must enter the ubiquitous language and each of these terms must be understood clearly by all members. During requirements gathering sessions and planning meetings, these terms must be captured and made available to everybody. Technical terms from the development team and business terms not relevant for the piece of software being implemented MUST NOT enter the ubiquitous language.</div> <div class="separator" style="clear: both; text-align: left;"><strong>Capturing the ubiquitous language</strong></div> <p>In order to capture the ubiquitous language, it is mandatory that you work on a iterative software development environment. Trying to capture the ubiquitous language up-front could straitjacket the whole process, inhibiting team members to make the necessary changes along the way. As the language is used to express the business requirements, it is natural that it evolves during the lifetime of the project, where new terms are added, deleted and also re-defined.</p> <p>Methodologies like Extreme Programming (XP) says that the only documentation should be the code. Not even comments on the code are appreciated, since they can easily get out of sync with the code. The code should be the only documentation since it is the only one that represents exactly what the system does.</p> <p>On the other hands, we have UML (Unified Modeling Language), that in theory, should be a great candidate to document the ubiquitous language since the whole purpose of UML was to document requirements and express them in a language that is common to developers and business people.</p> <p>In summary, showing code during discussions with domain experts, testers and other members of the team during a design session is not exactly a fantastic idea. Also, using just UML, because of its bureaucracy, rules and details is also a bad idea. The whole UML notation could easily straitjacket the creative process during the exercise.</p> <p>There are many discussions about what would be the best way to capture the ubiquitous language. My preferred way is to draw diagrams (boxes and arrows mixed with some well understood UMLish notation) where each box represent a "<strong>domain object</strong>" (aka domain concept). A domain object can be anything that is expressed by the business, like <em>client, organisation, product, route specification,  sales system</em>, etc. They would all be boxes. Add to it a few arrows linking the boxes and with just a couple of words explaining how they related to each other. Sometimes a mixture of a class and sequence diagram (or an active diagram) can be very helpful, but don't get to picky about any notation. Preferably, draw on a white board, take a picture and store that on the wiki. For further sessions, just open the wiki and re-draw just the bit of the design that is important to the feature being discussed. Make the necessary adjusts on the white board, take another picture and stored it on the wiki again. There is much more to that, if you want to dive into <a href="http://www.agilemodeling.com/%20%20">agile modeling</a>, but I will leave it to another post.</p> <p>This goes way beyond transforming nouns and verbs into classes and methods. Taking the examples above, for example, <em>client, organisation</em> and <em>products</em> could be transformed in entities; <em>route specification</em> could be a strategy class used by a <em>routing service</em> (that would also need to be added to the diagram and to the ubiquitous language); <em>sales system</em> would be an external system that we need to integrate to, etc.</p> <p><strong>Making the code more expressive</strong></p> <div class="separator" style="clear: both; text-align: left;">The code should reflect all concepts exposed by the model. Classes and methods should be named according to the names defined by the domain. Associations, compositions, aggregations and sometimes even inheritances should be extracted from the model.</div> <div class="separator" style="clear: both; text-align: left;">Sometimes, during implementation, we realise that some of the domain concepts discussed and added to the model don't actually fit well together and some changes are necessary. When it happens, developers should discuss the problems and/or limitations with the domain experts and refactor the domain model in order to favour a more precise implementation, without ever distorting the business significance of the design.</div> <div class="separator" style="clear: both; text-align: left;">Ultimately, the code is the most important artefact of a software project and it needs to work efficiently. Regardless of what many experts in the subject say, code implementation will have some impact on the design. However, we need to be careful and very selective about which aspects of the code can influence design changes. As a rule, try as much as you can to never let technical frameworks limitations influence your design, but as we know, every rule has exceptions.</div> <div class="separator" style="clear: both; text-align: left;">A common implementation problem that very often get in the way is mapping objects to databases using ORM tools. In this case, bending the model a little bit in favour of a more <em>realistic </em>relation among entities is not a bad thing. Just make sure that changes like that are represented in the model and understood by everyone involved.</div> <div class="separator" style="clear: both; text-align: left;"><strong>DOs and DON'Ts </strong></div> <ul> <li>Don't try to model everything.<strong> </strong>Focus on the core of your application. We are not working on a waterfall or Unified Process project here. </li> <li>Try to model just the key concepts of the domain problem;</li> <li>Do not clutter your models with too much details. Keep it focused on the main responsibilities;</li> <li>Limit your discussions and changes in the model to the business concepts (domain objects) related to the user story being discussed;</li> <li>Don't add architectural concepts like DAOs, Actions, etc. We are not writing implementation diagrams. </li> <li>As your application grows, break the application into multiple models (domains), explicitly defining the context and boundaries within which a model applies. This is called <a href="http://domaindrivendesign.org/node/91">Bounded Context</a> in Domain-Driven Design.</li> <li>Avoid thinking purely on the implementation when designing your model. Understanding and modeling the business is the most important thing here. </li> </ul> <div class="separator" style="clear: both; text-align: left;"><strong>Challenges of a Model-Driven Design</strong><strong> </strong></div> <div class="separator" style="clear: both; text-align: left;"><a href="http://domaindrivendesign.org/node/121">Model-Driven Design (MDD)</a> is more an art than a science. It takes a lot of practice and willingness to get it going and get it right. Refactoring towards deeper insights must be seen as a positive and essential part of the project development. TDD and continuous integration are also essential for any agile and domain-driven application.</div> <div class="separator" style="clear: both; text-align: left;">The goal of <a href="http://domaindrivendesign.org/node/121">MDD</a> is having the software expressing a <a href="http://domaindrivendesign.org/node/101">deep</a> and <a href="http://domaindrivendesign.org/node/131">supple</a> design.<a href="http://www.blogger.com/goog_972650201"><br /></a></div> <div class="separator" style="clear: both; text-align: left;"><a href="http://domaindrivendesign.org/node/101"><br /></a></div> <div class="separator" style="clear: both; text-align: left;">Last buy not least, developers with good <a href="http://en.wikipedia.org/wiki/Object-oriented_design">Object-Oriented Design</a> skills are needed in the project. The lack of design skills could easily transform ANY software project in a total failure in the long term.</div> <div class="separator" style="clear: both; text-align: left;"><a href="http://domaindrivendesign.org/node/101"><br /></a></div> <div class="separator" style="clear: both; text-align: left;">Source</div> <div class="separator" style="clear: both; text-align: left;"><a href="http://domaindrivendesign.org/">http://domaindrivendesign.org/</a></div> <div class="separator" style="clear: both; text-align: left;"><a href="http://domaindrivendesign.org/node/91%7C">http://domaindrivendesign.org/node/91|</a></div> <div class="separator" style="clear: both; text-align: left;"><a href="http://domaindrivendesign.org/node/132">http://domaindrivendesign.org/node/132</a></div> <div class="separator" style="clear: both; text-align: left;"><a href="http://domaindrivendesign.org/node/121">http://domaindrivendesign.org/node/121</a></div> <div class="separator" style="clear: both; text-align: left;"><a href="http://www.agilemodeling.com/">http://www.agilemodeling.com/</a></div> <div class="blogger-post-footer"><img src="https://blogger.googleusercontent.com/tracker/8424060401701893376-2937834842513651382?l=craftedsw.blogspot.com" alt="" width="1" height="1" /></div><img src="http://feeds.feedburner.com/~r/ValtechUK/~4/jBiaNCMs_9k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.valtech.co.uk/development/one-team-one-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		<feedburner:origLink>http://blog.valtech.co.uk/development/one-team-one-language/</feedburner:origLink></item>
		<item>
		<title>The Wolf in Sheep’s Clothing</title>
		<link>http://feedproxy.google.com/~r/ValtechUK/~3/3BhQodHaY34/</link>
		<comments>http://blog.valtech.co.uk/craftsmanship/the-wolf-in-sheeps-clothing/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 02:51:00 +0000</pubDate>
		<dc:creator>Sandro Mancuso</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[craftsmanship]]></category>

		<guid isPermaLink="false" />
		<description><![CDATA[In the last few years, I've noticed that the majority of the projects that I've  participated roughly  followed the same design. Speaking to colleagues and friends, the great majority said that they were also following the same design. It's what I call...]]></description>
			<content:encoded><![CDATA[<p>In the last few years, I've noticed that the majority of the projects that I've  participated roughly  followed the same design. Speaking to colleagues and friends, the great majority said that they were also following the same design. It's what I call "<strong>ASD</strong>"  design (Action-Service-DAO).</p> <div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="http://1.bp.blogspot.com/_ONTWYUiOUvw/TBIWQTGjE5I/AAAAAAAAAH4/Y98_C2MOjZU/s1600/ASD.png"><img src="http://1.bp.blogspot.com/_ONTWYUiOUvw/TBIWQTGjE5I/AAAAAAAAAH4/Y98_C2MOjZU/s400/ASD.png" border="0" alt="" width="400" height="35" /></a></div> <p><span style="font-size: x-small;"><em>by Action we mean a Struts Action, Spring Controller, JSF backing bean, etc. Any class that handles an action triggered by the user interface. </em></span></p> <p>We can  argue that there is nothing really wrong about this approach since if we  map that to a <a href="http://craftedsw.blogspot.com/2010/05/mvc-and-multi-tier-architecture.html">three-tier architecture</a>, that is followed by the majority  of the applications, the ASD classes would be in the right places,  keeping a good isolation between the tiers.</p> <div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="http://2.bp.blogspot.com/_ONTWYUiOUvw/TBIYlIGFyUI/AAAAAAAAAIA/eaKCuxwpbCk/s1600/ASD_3Tier.png"><img src="http://2.bp.blogspot.com/_ONTWYUiOUvw/TBIYlIGFyUI/AAAAAAAAAIA/eaKCuxwpbCk/s400/ASD_3Tier.png" border="0" alt="" width="400" height="62" /></a></div> <p>One of the problems of this approach is when services are created randomly, with different granularities, <a href="http://craftedsw.blogspot.com/2010/04/cohesion-cornerstone-of-oo.html">low cohesion</a> and with a weak representation of the business domains. Services end up being function libraries, almost like an utility class where all "functions" related to a specified "module" are grouped. When it comes to DAOs, the situation is not very different. DAOs are developed in a way that they become utility classes where sometimes we find a single DAO with all queries, inserts, delete, updates for an entire module or sometimes you find one DAO per entity. Either way, regardless what the query returns (or what it is its intention), or any rules related to updates or deletes, the methods will go to the same class. As the application grows, the code becomes something like this:</p> <div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="http://4.bp.blogspot.com/_ONTWYUiOUvw/TBIvqV_26pI/AAAAAAAAAIQ/QPE-uckZXF4/s1600/ASD_Mess.png"><img src="http://4.bp.blogspot.com/_ONTWYUiOUvw/TBIvqV_26pI/AAAAAAAAAIQ/QPE-uckZXF4/s400/ASD_Mess.png" border="0" alt="" width="400" height="141" /></a></div> <p> </p> <p><span id="more-309"></span>Looking at the picture above, can we really say that it is object-oriented programming? As services and DAOs don't strongly represent business concepts, the code becomes procedural. I don't want to bang on about the advantages of OOP over Procedural code. I believe that too many people have already discussed that over the past 30 years. My point here is to discuss what a "design" like that can do to an application.</p> <p><strong>Following bad examples</strong><br /><strong><br /></strong><br />Unfortunately, in software development, bad examples are easier to be followed than good examples. With a non-expressive business model like that, the services get overloaded with methods. When adding new features to the application, developers need to go through all the methods of a service to see if there is already a method that does what they need. Due to the <a href="http://craftedsw.blogspot.com/2010/04/cohesion-cornerstone-of-oo.html">lack of cohesion</a> and method explosion in the services, many developers will just add a new method in there, that can be very similar to existing ones, instead of re-factor the existing ones. This leads to services with confusingly similar methods and a lot of duplication. As a chain of "bad" events, the more methods a service has, the more classes depending on it the application will have. Many dependencies means that re-factoring the class would be harder, discouraging any one willing to improve the quality of the code.</p> <p>Duplication does not happen just inside a single service. It's also very common to find different services with very similar methods, if not the same. In general, this is due for the <a href="http://craftedsw.blogspot.com/2010/06/object-oriented-design-principles-part.html">lack of clarity on the responsibility</a> of each service. According to the feature that developers are working on, they will choose a service to add (or reuse) the methods they need. If the responsibility and granularity of each service is not clear, business rules related to a certain area of the business will be spread all over the place since different developers will think that the method will belong to different classes.</p> <p><strong>Exposing DAOs to the presentation tier</strong></p> <p>Another side effect of this approach is that since the DAOs are also "utility classes" with no business meaning (it just has an architectural meaning), some developers can easily expose the DAOs to the actions, without going through the services. Let's give more meaningful names and more details about the Action 4 and DAO 4 shown above. Let's call them ClientAction and ClientDAO.</p> <div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="http://4.bp.blogspot.com/_ONTWYUiOUvw/TBJr-biWIjI/AAAAAAAAAIY/9aKLt2EtXLQ/s1600/ClientAction_DAO.png"><img src="http://4.bp.blogspot.com/_ONTWYUiOUvw/TBJr-biWIjI/AAAAAAAAAIY/9aKLt2EtXLQ/s400/ClientAction_DAO.png" border="0" alt="" width="400" height="70" /></a></div> <p>Here the user interface needs to display a list of clients. ClientDAO has a method that returns a list of clients. In theory this may make sense. The most used argument in favour of this approach instead of adding a "ClientService" in between the ClientAction and the ClientDAO is that the service would have a method that just delegates the call to the DAO. The service layer, in this case, would be considered redundant and just pointless extra work.</p> <div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="http://1.bp.blogspot.com/_ONTWYUiOUvw/TBLIJH_oItI/AAAAAAAAAIg/xPmS5p-sBig/s1600/ClientASD_allClients.png"><img src="http://1.bp.blogspot.com/_ONTWYUiOUvw/TBLIJH_oItI/AAAAAAAAAIg/xPmS5p-sBig/s400/ClientASD_allClients.png" border="0" alt="" width="400" height="56" /></a></div> <p>Looking at this isolated scenario, having a service in the middle really looks a bit overkill and unnecessary. However, we will probably want to do more things with a client. We will probably want to create a new client, delete or update an existing client.</p> <div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="http://4.bp.blogspot.com/_ONTWYUiOUvw/TBLNxcSexsI/AAAAAAAAAIw/31fFgxmPgaw/s1600/ClientAction_DAO_allMethods.png"><img src="http://4.bp.blogspot.com/_ONTWYUiOUvw/TBLNxcSexsI/AAAAAAAAAIw/31fFgxmPgaw/s400/ClientAction_DAO_allMethods.png" border="0" alt="" width="400" height="132" /></a></div> <p>Here is where the problems begin. Very rarely, we have a pure <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> application. In general, many business rules have to be performed before or after any changes are made in the persistence tier (generally a database). For example, before inserting a new client, a credit check needs to be performed. When deleting a new client, we need to make sure that there is no outstanding balance for that client and close his or her account. We also need to archive all the orders for this client.  Whatever the application's business rules dictate. Multiple entities (or database operations) may be involved in a operation like that. We need to be able to define transaction boundaries. Besides CRUD operations, we will also have all business methods like check if client has credit, add orders to a client, etc. This is too much for a single DAO to handle. DAOs should not perform any business logic and should be hidden from the presentation tier. It should be hidden (encapsulated) even from different services. DAOs should just deal with the persistence. Business logic and transaction boundaries should be controlled by a class with business responsibilities, that in the case of this "poor" design, it would be a service.</p> <p> </p><div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="http://1.bp.blogspot.com/_ONTWYUiOUvw/TBLL4e4PlhI/AAAAAAAAAIo/D_GYk7jKRn8/s1600/ClientASD_allMethods.png"><img src="http://1.bp.blogspot.com/_ONTWYUiOUvw/TBLL4e4PlhI/AAAAAAAAAIo/D_GYk7jKRn8/s400/ClientASD_allMethods.png" border="0" alt="" width="400" height="82" /></a></div> <p>So even having a few methods in the service that just delegate the <a href="http://craftedsw.blogspot.com/2010/06/object-oriented-design-principles-part.html">responsibility</a> to a DAO, it is still a price worth paying. The service should hide (encapsulate) the details of it's implementation. A client code does not need to know how and where the data is persisted.</p> <p>OK, enough of this. Exposing DAOs to the presentation tier is WRONG. Let's move on.</p> <p><strong>Moving away from the procedural code</strong> <strong>(baby steps)</strong></p> <p>The first thing to do to move away from the procedural code is to make your code more expressive and aligned to the business. We need to narrow the gap between developers and domain experts (business analysts, users, product owner or whoever knows the business rules) so we all start speaking the same language. The code must be written in a way that it expresses the business and not just architectural concepts that means nothing to the business. Actions, Services and DAOs are technical terms with no connection to any business term.</p> <p>There are a few techniques that can be applied (or even combined) in order to make it possible. In future posts, I'll be talking about some of these techniques in more details. I know, it's frustrating that I will not tell you right now how to do it after have spending all this time criticising the ASD procedural design. The important thing for now is to know that what looks a good solution, since it is used by many different people and in many different projects, may not be as good as it seems.</p> <p>In the meantime, there is something that we can start doing to our code in order to reduce the mess and make the necessary refactorings easier in the future.</p> <p><strong>Preparing your code for an easier transition</strong></p> <p>The following advices will help us to get our code to a point where it can be easily refactored into a more domain (business) focused approach in the future. It will still be a bit procedural but will be much more well organised and a notion of components (business components) will start to emerge.</p> <p>1. Identify key concepts (domains) in your application. (e.g. Client, Order, Invoice, Trip, Itinerary, etc)<br />2. You can create / refactor services for each one of the key domains.<br />3. Try to keep a well balanced granularity for all services.<br />4. Avoid services for small parts of the domain. For example, do not create a service for line items. Line items should be handled by the OrderService.<br />5. Services are not allowed to manipulate multiple domains (with exceptions of whole-part relations - compositions)<br />6. DAOs are encapsulated by the services and never accessed by any other class.<br />7. Not every service must access a DAO, but any DAO must be accessed by one and only one service.<br />8. Services must delegate operations to other services if the operation is related to a different domain from the one the service is handling.<br />9. Services talk to each other. DAOs never talk to each other.<br />10. Parts (like a line item) are never exposed by a service. Service always exposes the whole (like Order). Parts are accessed via the whole. (e.g. order.getLineItems();)</p> <p>With the following rules, our procedural code starts looking more like meaningful objects, with a reasonably well defined interface and some significance in terms of business.</p> <div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="http://2.bp.blogspot.com/_ONTWYUiOUvw/TBLp6zdyr7I/AAAAAAAAAI4/xVjr-Pz6t7w/s1600/ASD_normalised.png"><img src="http://2.bp.blogspot.com/_ONTWYUiOUvw/TBLp6zdyr7I/AAAAAAAAAI4/xVjr-Pz6t7w/s400/ASD_normalised.png" border="0" alt="" width="400" height="141" /></a></div> <p><br />As mentioned before, this is still a bit procedural but this design already solve a some of the problems discussed earlier like having more meaningful and specific services. The <a href="http://craftedsw.blogspot.com/2010/06/object-oriented-design-principles-part.html">responsibility </a>and boundaries of each service are more defined, making it easier for developers to look for implemented methods and re-use what it is in there, reducing duplication.</p> <p>In future posts I'll be talking about the next steps towards a more expressive and business focused code, less procedural and more object-oriented.</p> <p><em>If you are curious about the next steps and can't wait for my posts, have a look at:</em><br /><a href="http://domaindrivendesign.org/">http://domaindrivendesign.org/</a><br /><a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">http://en.wikipedia.org/wiki/Behavior_Driven_Development</a><br /><a href="http://en.wikipedia.org/wiki/Model-Driven_Architecture">http://en.wikipedia.org/wiki/Model-Driven_Architecture</a><br /><a href="http://en.wikipedia.org/wiki/OOD">http://en.wikipedia.org/wiki/OOD</a></p><div class="blogger-post-footer"><img src="https://blogger.googleusercontent.com/tracker/8424060401701893376-4099309548608407319?l=craftedsw.blogspot.com" alt="" width="1" height="1" /></div><img src="http://feeds.feedburner.com/~r/ValtechUK/~4/3BhQodHaY34" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.valtech.co.uk/craftsmanship/the-wolf-in-sheeps-clothing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		<feedburner:origLink>http://blog.valtech.co.uk/craftsmanship/the-wolf-in-sheeps-clothing/</feedburner:origLink></item>
		<item>
		<title>Object-Oriented Design Principles – Part 2</title>
		<link>http://feedproxy.google.com/~r/ValtechUK/~3/ToGnOR-Wcxg/</link>
		<comments>http://blog.valtech.co.uk/architecture/object-oriented-design-principles-part-2/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 18:22:00 +0000</pubDate>
		<dc:creator>Sandro Mancuso</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[OO]]></category>

		<guid isPermaLink="false" />
		<description><![CDATA[In the first part of this Object-Oriented Design principles series, I covered the Single Responsibility Principle (SRP). I had also covered the Liskov Substitution Principle (LSP) on a previous post. So let's move on to another Object-Oriented Design P...]]></description>
			<content:encoded><![CDATA[<i>In the <a href="http://craftedsw.blogspot.com/2010/06/object-oriented-design-principles-part.html">first part</a> of this Object-Oriented Design principles series, I covered the <a href="http://craftedsw.blogspot.com/2010/06/object-oriented-design-principles-part.html">Single Responsibility Principle (SRP)</a>. I had also covered the <a href="http://craftedsw.blogspot.com/2010/06/liskov-substitution-principle-lsp.html">Liskov Substitution Principle (LSP)</a> on a previous post. So let's move on to another Object-Oriented Design Principle.</i><br /><br /><b>The Open Closed Principle (OCP)</b> <br /><br /><blockquote><i>Software entities (classes, modules, functions, etc.) should be open  for extension, but closed for modification</i></blockquote><br />We know that requirements will change, new requirements will come and we will need to change some existing code during the life of a project. However, when a change in one place results in a cascade of changes in other classes, that's a sign that the design is not quite right. Changes causing side effects are undesirable since it makes the program unstable, rigid and fragile where parts can not be re-used. <br /><br />The Open Closed Principle target all problems described above. Being open for extension means that modules can be extended  in order to make them behave in a new or different way. Closed for modification means that we should not change existing code unless that we are fixing a bug.<br /><br />There were two proposed ways to achieve the OCP and both use inheritance:<br /><ol><li> Dr. <a href="http://en.wikipedia.org/wiki/Bertrand_Meyer" title="Bertrand Meyer">Bertrand Meyer</a>, that coined the <a href="http://en.wikipedia.org/wiki/Open/closed_principle">Open Closed Principle in 1988</a>, proposes the use of inheritance. When a new feature or a changing on an existing feature is needed, a new class must be created, inheriting from the old one. The new class does not necessarily keep the same interface.  </li><li>A few other <a href="http://en.wikipedia.org/wiki/Open/closed_principle">authors redefined the OCP</a> in the 90ies. Basically they suggested the use of abstract base classes and concrete implementations. The abstract class would define the interface that would be closed to modifications. The concrete classes would implement the abstract class interface (open for extension) and multiple implementations could be created and polymorphically  substituted for each other. </li></ol>Nowadays, with the evolution of frameworks with dependency injection capabilities, a better approach would be having a client class pointing to an plain Java  interface and inject the implementations.  <br /><br />OCP is an old OOP design principle and is one of the most important ones, due to the problems it solves. It can be an interesting approach in cases where the bureaucracy of changing old code and deployment to the production environment is very high. Some companies may ask for code reviews, a long test cycle (non-automated), documentation, etc. With OCP, no existing code is changed and just new code is added. <br /><br />However, in a more agile environment, good test coverage, IDEs that have good re-factoring tools (like Eclipse, Idea, etc) I wouldn't be too worried about changing classes and interfaces but this would not invalidate all the advantages of the OCP.<br /><br />Source<br /><a href="http://en.wikipedia.org/wiki/Solid_%28object-oriented_design%29">http://en.wikipedia.org/wiki/Solid_%28object-oriented_design%29</a> <br /><a href="http://en.wikipedia.org/wiki/Open/closed_principle">http://en.wikipedia.org/wiki/Open/closed_principle</a><br /><a href="http://www.objectmentor.com/resources/articles/ocp.pdf">http://www.objectmentor.com/resources/articles/ocp.pdf</a><br /><a href="http://en.wikipedia.org/wiki/Design_by_Contract">http://en.wikipedia.org/wiki/Design_by_Contract</a><br /><a href="http://en.wikipedia.org/wiki/Information_hiding">http://en.wikipedia.org/wiki/Information_hiding</a><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8424060401701893376-356304251367071023?l=craftedsw.blogspot.com' alt='' /></div><img src="http://feeds.feedburner.com/~r/ValtechUK/~4/ToGnOR-Wcxg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.valtech.co.uk/architecture/object-oriented-design-principles-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.valtech.co.uk/architecture/object-oriented-design-principles-part-2/</feedburner:origLink></item>
		<item>
		<title>Defining and Prioritising a Backlog</title>
		<link>http://feedproxy.google.com/~r/ValtechUK/~3/3rnpa8FjDBU/</link>
		<comments>http://blog.valtech.co.uk/agile/defining-and-prioritising-a-backlog/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 14:58:45 +0000</pubDate>
		<dc:creator>Mashooq Badar</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Development Process]]></category>
		<category><![CDATA[backlog]]></category>
		<category><![CDATA[user story]]></category>

		<guid isPermaLink="false">http://mashb.wordpress.com/?p=123</guid>
		<description><![CDATA[What is the best way to review a backlog? How do you ensure that it is "complete"? How do you ensure that the prioritisation reflects the business vision and goals? When first faced with a backlog, you are often overwhelmed by the long list of userstories. The most important step is to set a context [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mashb.wordpress.com&#038;blog=7354608&#038;post=123&#038;subd=mashb&#038;ref=&#038;feed=1" />]]></description>
			<content:encoded><![CDATA[<p>What is the best way to review a backlog? How do you ensure that it is "complete"? How do you ensure that the prioritisation reflects the business vision and goals?</p>
<p>When first faced with a backlog, you are often overwhelmed by the long list of userstories. The most important step is to set a context for these userstories. Are these userstories organised in a hierarchy of “epics”? This hierarchy will help set a context. But first we need to understand what these epics mean at the highest level. Do they represent a user’s high-level goals or are they merely there as a container for some loosely related stories?</p>
<p>When reviewing a backlog for completion it is vitally important that the stories are defined in a context. The context can take different forms depending on the nature of the application. For example if an application has a clear high-level flow that the user journeys along then the epics may be defined as activities in this flow and the userstories can be grouped under each epic representing the functionality required for this activity. This <a href="http://www.agileproductdesign.com/blog/the_new_backlog.html">article</a> by Jeff Patton presents such an approach. However, your application my exhibit a more random usage scenario. In this case epics representing high-level user goals may represent the best context for the stories. You can also provide references to other artefacts such as user journeys/wireframes to further enrich the context. This <a href="http://tynerblain.com/blog/2009/07/06/writing-complete-user-stories">article</a> by Scott Sehlhorst is an interesting discussion of setting a context for user stories.</p>
<p>This grouping of userstories by a context also helps to manage their prioritisation. You can individually prioritise stories within each epic and then also prioritise the epics. Note that just because one epic has a higher priority does not mean that all its child userstories are of a higher priority. You may discover that only the first few userstories can provide enough functionality that further work on that epic is of a lower priority then working on another epic.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mashb.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mashb.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mashb.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mashb.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mashb.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mashb.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mashb.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mashb.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mashb.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mashb.wordpress.com/123/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mashb.wordpress.com&blog=7354608&post=123&subd=mashb&ref=&feed=1" /><img src="http://feeds.feedburner.com/~r/ValtechUK/~4/3rnpa8FjDBU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.valtech.co.uk/agile/defining-and-prioritising-a-backlog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.valtech.co.uk/agile/defining-and-prioritising-a-backlog/</feedburner:origLink></item>
		<item>
		<title>The Liskov Substitution Principle (LSP)</title>
		<link>http://feedproxy.google.com/~r/ValtechUK/~3/SXDti4YXrLc/</link>
		<comments>http://blog.valtech.co.uk/architecture/the-liskov-substitution-principle-lsp/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 00:50:00 +0000</pubDate>
		<dc:creator>Sandro Mancuso</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[OO]]></category>

		<guid isPermaLink="false" />
		<description><![CDATA[The Liskov Substitution Principle was initially introduced by Barbara Liskov in a 1987 conference keynote address entitled  Data abstraction and hierarchy. LSP is also part of SOLID, a group of five Object-Oriented Design Principles put together by Rob...]]></description>
			<content:encoded><![CDATA[The Liskov Substitution Principle was initially introduced by <a href="http://en.wikipedia.org/wiki/Barbara_Liskov" title="Barbara Liskov">Barbara Liskov</a> in a 1987 conference keynote address entitled  <i>Data abstraction and hierarchy.</i> LSP is also part of <a href="http://en.wikipedia.org/wiki/Solid_%28object-oriented_design%29">SOLID</a>, a group of five Object-Oriented Design Principles put together by Robert C. Martin in the early 2000s. <i> </i><br /><br /><blockquote><b><i>Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.</i></b></blockquote><br />The LSP's summary above looks quite obvious. If the calling code was written to use a base class, replacing it with a sub-class (inheritance) should make no difference to the calling code. That means, the calling code should not be changed and should be totally agnostic about which implementation is being used.<br /><br />LSP's importance is noticed mainly when it is violated. If a subclass causes changes on the calling code, that means, the calling code needs to test which subclass it is dealing with (instanceof, casting, etc), the code is violating the Liskov Substitution Principle and also the Open Closed Principle. This violation causes high coupling, low cohesion and a cascade of changes. <br /><br /><b>Violation of Liskov Substitution Principle</b><br /><br /><pre class="brush: java">public void drawShape(Shape s) {<br />    if (s instanceof Square) {<br />        drawSquare((Square) s);<br />    } else if (s instanceof Circle){<br />        drawCircle((Circle) s);<br />    }<br />}<br /></pre><br />The Liskov Substitution Principle also imposes a few rules that the sub-classes must obey. It bears a certain resemblance with <a href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a>'s <a href="http://en.wikipedia.org/wiki/Design_by_Contract">Design by Contract</a> in that it considers the interaction of subtyping with pre- and postconditions<br /><br /><blockquote><i>...when redefining a routine [in a derivative], you may only replace its precondition by a weaker one, and its postcondition by a stronger one.</i></blockquote><br />This means the sub-classes must accept everything that the base class accepts (pre-condition) and must conform to all postconditions of the base class. <br /><br /><b>Example of a more subtle violation</b><br /><pre class="brush: java">public class Rectangle {<br />    private int height;<br />    private int width;<br /><br />    public Rectangle(int height, int width) {<br />        this.height = height;<br />        this.width = width;<br />    }<br />    public int getHeight() {<br />        return this.height;<br />    }<br />    public void setHeight(int height) {<br />        this.height = height;<br />    }<br />    public int getWidth() {<br />        return this.width;<br />    }<br />    public void setWidth(int width) {<br />        this.width = width;<br />    }<br />}<br /><br />public class Square extends Rectangle {<br /><br />    public Square(int size) {<br />        super(size, size);<br />    }  <br />    public int getHeight() {<br />        return super.height;<br />    }<br />    public int getWidth() {<br />        return super.width;<br />    }<br />}<br /></pre><br />In the code above, a Square <b>IS A</b> Rectangle. Note that a rectangle can have different sizes for width and height, but in a square, height and width must be of the same size. What would happen in the following code is executed ?<br /><br /><pre class="brush: java">Rectangle r = new Square();<br />r.setHeight(5);<br />r.setWidth(6);<br /></pre><br />We should not allow this to happen since that would make the Square object invalid. In a square, height and width must always be the same. A quick fix for this would be to override the setter methods:<br /><br /><pre class="brush: java">public class Square extends Rectangle {<br /><br />    public Square(int size) {<br />        super(size, size);<br />    }  <br />    public int getHeight() {<br />        return super.height;<br />    }<br />    public int getWidth() {<br />        return super.width;<br />    }<br />    public void setHeight(int height) {<br />        super.height = height;<br />        super.width = width;<br />    }<br />    public void setWidth(int width) {<br />        super.width = width;<br />        super.height = width;<br />    }<br />}<br /></pre><br />Although this approach would fix the problem, is a violation of the Liskov Substitution Principle since the methods will weaken (violate) the postconditions  for the Rectangle setters, which state that dimensions can be modified independently.<br /><br />One interesting thing to note is that if we analyse the Rectangle and Square classes in isolation, they are consistent and valid. However, when we look at how the classes can be used by a client program, we realise that the model is broken. <br /><br />Every time you get yourself adapting a sub-class so that it does not break or its state does not become invalid if used in the context of a super-class, this is a clue that the sub-class should not be a sub-class at all. <br /><br />In this example, maybe a Square is not a Rectangle. Square should not have height and width to start with. It should just have size. And since a Square is not a Rectangle, it should never be used in a Rectangle context. <br /><br /><pre class="brush: java">public class Square {<br />    int size;<br />    <br />    public Square(int size) {<br />        this.size = size;<br />    }  <br />    public int getSize() {<br />        return this.size;<br />    }<br />    public void setSize(int size) {<br />        this.size = size;<br />    }<br />}<br /></pre><br />We can not validate a model in isolation. A model should be validated just in terms of its clients. <br /><br />Source<br /><a href="http://en.wikipedia.org/wiki/Liskov_substitution_principle">http://en.wikipedia.org/wiki/Liskov_substitution_principle</a><br /><a href="http://www.objectmentor.com/resources/articles/lsp.pdf">http://www.objectmentor.com/resources/articles/lsp.pdf</a><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8424060401701893376-5776600455144649729?l=craftedsw.blogspot.com' alt='' /></div><img src="http://feeds.feedburner.com/~r/ValtechUK/~4/SXDti4YXrLc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.valtech.co.uk/architecture/the-liskov-substitution-principle-lsp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.valtech.co.uk/architecture/the-liskov-substitution-principle-lsp/</feedburner:origLink></item>
	</channel>
</rss>
