<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>hexagonalarchitecture &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/hexagonalarchitecture/</link>
	<description>Feed of posts on WordPress.com tagged "hexagonalarchitecture"</description>
	<pubDate>Fri, 01 Jan 2010 07:44:09 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[callbacks break hexagonal architectures]]></title>
<link>http://silkandspinach.net/2009/03/16/callbacks-break-hexagonal-architectures/</link>
<pubDate>Mon, 16 Mar 2009 21:33:06 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2009/03/16/callbacks-break-hexagonal-architectures/</guid>
<description><![CDATA[I just figured out why callback style APIs are harder to test (and harder to deal with in general). ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I just figured out why callback style APIs are harder to test (and harder to deal with in general). It&#8217;s because they break one of the essential ingredients of a hexagonal architecture: <a href="http://silkandspinach.net/2005/03/22/the-middle-hexagon-should-be-independent-of-the-adapters/">the middle hexagon should be independent of the adapters</a>. Here&#8217;s why&#8230;</p>
<p>In order to use a callback API, one or more of our application classes must implement the callback method(s), and must therefore conform to some abstraction defined by the API&#8217;s provider. So our classes must depend on the API. Which means that the API can&#8217;t be easily mocked or stubbed. We have to treat our callback objects as being part of the adapter for that API, and test the rest of the application by mocking or stubbing them.</p>
<p>In fact, now I&#8217;ve written it down it&#8217;s trivially obvious, and hardly worth saying.</p>
<p>As you were. </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[the "anchor adapter"]]></title>
<link>http://silkandspinach.net/2009/01/22/the-anchor-adapter/</link>
<pubDate>Thu, 22 Jan 2009 21:59:01 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2009/01/22/the-anchor-adapter/</guid>
<description><![CDATA[Warning: academic theorizing and hypothesizing follow. Oh, and half-baked pontification. I just fini]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Warning:</strong> academic theorizing and hypothesizing follow. Oh, and half-baked pontification.</p>
<p>I just finished refactoring <a href="http://reek.rubyforge.org">reek</a> to drive in a major new chunk of functionality (configuration files) which I&#8217;ll release soon, when I&#8217;ve had time for some thorough testing.</p>
<p>The refactoring needed to accommodate the change was huge, occupying much of my free time over the course of two months. Pretty much the whole of the tool&#8217;s original architecture has been revised. Why so big and so complex? Because the original code relied heavily on constants and class methods; they helped me get the early versions written quickly, but they represented a significant barrier to long-term flexibility. I&#8217;ve been wondering why that should be; why do constants and class methods stand in the way of adaptable test-driven code?</p>
<p>I think the answer lies in viewing the application through the lens of <a href="http://silkandspinach.net/2005/11/28/gravity-and-software-adaptability/">Hexagonal Architecture</a>. Let me explain&#8230;</p>
<p>It seems to me that constants, global variables, classes, class methods, etc all live in a space that&#8217;s &#8220;anchored&#8221; to the runtime environment, which is itself a singleton. Anything anchored to that singleton is going to hinder the independence and isolatedness of unit tests, and also reduce the application&#8217;s flexibility in well-known ways. So far so standard. Now, suppose we model the singleton as a notional point that is external to the application. Hexagonal Architecture tells us we must access the singleton via an <em>Adapter</em> &#8212; in this case, an Adapter provided by the programming language and/or runtime. I&#8217;ll refer to the singleton as the application&#8217;s Anchor, and therefore claim that it is accessed through language features in an Anchor Adapter.</p>
<p>Now, I believe that <a href="http://silkandspinach.net/2005/03/22/the-middle-hexagon-should-be-independent-of-the-adapters/">the Domain Middle should not depend directly on Adapters</a>. So any code that makes direct use of the Anchor Adapter must therefore be considered outside of the Domain Middle, and hence part of an Adapter &#8212; and hence also inherently outside the space where unit tests live comfortably.</p>
<p>Which is why constants and class methods add friction to unit testing.</p>
<p>Or rather: This model fits nicely with my penchant for Hexagonal Architecture, and lets me justify my unease at testing in and around class methods. And probably adds nothing to our understanding of software development. </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[gravity and metaphors at the MDDA]]></title>
<link>http://silkandspinach.net/2007/10/29/gravity-and-metaphors-at-the-mdda/</link>
<pubDate>Mon, 29 Oct 2007 21:06:31 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2007/10/29/gravity-and-metaphors-at-the-mdda/</guid>
<description><![CDATA[Dave Verwer at NWRUG has been crazykind enough to invite me to re-run a version of my hexagonal arch]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Dave Verwer at <a href="http://nwrug.org">NWRUG</a> has been <strike>crazy</strike>kind enough to invite me to re-run a version of my <a href="http://silkandspinach.net/2005/11/28/gravity-and-software-adaptability/">hexagonal architecture workshop</a> this month at the MDDA.  This is the session that, two years ago, had seventy of the world&#8217;s leading agilists <a href="http://www.willemvandenende.com/images/2005/xp_day_benelux/thursday/img_9094.jpg">standing on one leg</a>.  If you&#8217;re in Manchester on the evening of <a href="http://nwrug.org/events/november07/">November 20th</a>, why not hop along?</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[data classes at the application's edges]]></title>
<link>http://silkandspinach.net/2006/02/27/data-classes-at-the-applications-edges/</link>
<pubDate>Mon, 27 Feb 2006 22:05:46 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2006/02/27/data-classes-at-the-applications-edges/</guid>
<description><![CDATA[In Edge Case Bill de hÓra points out, as does Tony Coates, that a DataClass is not always a bad idea]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In <a href="http://www.dehora.net/journal/2006/02/edge_case_1.html/">Edge Case</a> Bill de hÓra points out, as does <a href="http://kontrawize.blogs.com/kontrawize/2006/02/objectoriented_.html">Tony Coates</a>, that a DataClass is not always a bad idea.  Both are responding to an <a href="http://martinfowler.com/bliki/GetterEradicator.html">assertion</a> made by Martin Fowler, that a DataClass is usually a sign of poor design.  And both use serialised objects as a counterexample.  I guess I&#8217;ve never thought of serialised objects as capable of having behaviour (since they generally live in media that don&#8217;t support it); and so perhaps I don&#8217;t even think of them as being sufficiently objecty to even count in the discussion.  So to me it&#8217;s a non-disagreement.</p>
<p>More interesting to my eyes is Bill&#8217;s use of the term &#8220;application edges&#8221;:</p>
<blockquote><p> &#8220;But when it comes to working at the application edges &#8211; at the network boundary, over HTTP, between applications, intra-app messaging &#8211; well, &#8220;I have a doubt.&#8221; [...] There&#8217;s a lot of system edges these days, and agreeing where the edges are is hard.&#8221;</p></blockquote>
<p>There are indeed a lot of edges these days.  And trying to think about them in the context of a layered model of the application&#8217;s architecture is likely to cause brain-ache.  Which is why I keep pushing the <a href="http://silkandspinach.wordpress.com/2005/11/28/gravity-and-software-adaptability/">hexagonal architecture</a> model.  It moves the application and domain objects into the centre, and surrounds them with adapters that connect to the rest of the world.  In this architecture, the &#8220;edges&#8221; have a natural symmetry, and their role in the application becomes easier to visualise.</p>
<p>So in the context of hexagonal adapters, some of Bill and Tony&#8217;s data classes will likely be GoF <a href="http://c2.com/cgi/wiki?MementoPattern">Mementos</a>, others are probably <a href="http://c2.com/ppr/checks.html#1">Whole Value</a> objects, and the rest probably really are blobs of data.  I would expect the Whole Value objects to have behaviour, but not the others.  But the real point, for me, is that the hexagonal architecture approach makes the use of these patterns clearer&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[gravity and software adaptability]]></title>
<link>http://silkandspinach.net/2005/11/28/gravity-and-software-adaptability/</link>
<pubDate>Mon, 28 Nov 2005 10:58:00 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2005/11/28/gravity-and-software-adaptability/</guid>
<description><![CDATA[During my &#8216;hexagonal architecture&#8217; session at XPday Benelux, the discussion gave me some]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://www.flickr.com/photos/silkandspinach/500835204/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/201/500835204_3ad30a6151_o.jpg" width="141" height="202" alt="stack" style="border:medium none;float:right;padding:10px;" /></a> During my &#8216;hexagonal architecture&#8217; session at <a href="http://silkandspinach.wordpress.com/2005/11/21/reflections-on-xpdays-benelux-2005/">XPday Benelux</a>, the discussion gave me some clues as to why I feel the &#8220;standard&#8221; layered architecture model is sub-optimal:  I realised that I feel as if I&#8217;m looking at a picture of a <em>pile</em> of stuff <em>from the side</em>.  Contrast this with a hexagonal model of the same system, in which I feel as though I&#8217;m looking <em>down</em> on the picture.</p>
<p>Why is this important?  And what relationship does it have to being agile?</p>
<p>The answer, I believe, lies in <a href="http://en.wikipedia.org/wiki/George_Lakoff">Lakoff</a>&#8217;s theory that metaphor shapes much of our thinking.  When I look at any architecture model I subconsciously impose a point of view on the picture, because my mind relates what I see now to previous experiences.  A layered model &#8220;looks like&#8221; a pile of books or building bricks; <a href="http://www.flickr.com/photos/silkandspinach/500829904/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/225/500829904_7505073fc0_o.jpg" width="175" height="121" alt="hexagonaltable" style="border:medium none;float:left;padding:10px;" /></a> a hexagonal model &#8220;looks like&#8221; an island on a map (another metaphor in itself!) or a table with chairs arranged around it.  The choice of metaphor is made deep in my perceptual system, helping me to make sense of anything I see.  And once the metaphor has been selected, my mind will then automatically supply it with a whole load of related beliefs, many learned as a baby.  Among these are the effects of gravity and mass, together with related implications of downward dependency.</p>
<p>These associations cause me to believe that the things at the bottom of the pile are hard to move or change.  Whereas in the hexagonal view I instinctively feel the system&#8217;s components are more loosely coupled &#8211; perhaps because they are associated only by proximity, and not by gravity.</p>
<p>So because of these deep-seated metaphorical associations, maybe we build less adaptable systems when we think of them in layers&#8230;?</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[ports and adapters architecture]]></title>
<link>http://silkandspinach.net/2005/07/25/ports-and-adapters-architecture/</link>
<pubDate>Mon, 25 Jul 2005 10:53:50 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2005/07/25/ports-and-adapters-architecture/</guid>
<description><![CDATA[Last month Alistair began using a new name for the Hexagonal Architecture pattern &#8211; he now cal]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Last month Alistair began using a new name for the Hexagonal Architecture pattern &#8211; he now calls it the <a href="http://c2.com/cgi/wiki?PortsAndAdaptersArchitecture">Ports and Adapters Architecture</a>.</p>
<p>Now I believe that names are immensely important, and so I applaud Alistair&#8217;s search for the right name for this concept.  But for some reason PortsAndAdapters rings no bells for me.  Maybe I&#8217;ve simply become used to the old name, or maybe I&#8217;m averse to change.  (That would be ironic for an agile coach, but I guess we all have comfort zones&#8230;)  So what is it with this new name &#8211; or what does the old name have instead?</p>
<p>Obviously I have no quibble with the &#8216;Adapters&#8217; part, because I&#8217;ve been using that term for long enough myself.  But &#8216;Ports&#8217;?  From that term I would tend to infer a fixed set of pre-existing conduits, sending and receiving signals from something specific.  Whereas I tend to think of a hexagonal architecture as something much more flexible, able to post adapters (more on this soon) to a less prescribed set of real-world entities.</p>
<p>I tend to view the physical world as an amorphous soup to which the software system can connect adapters in fluid ways.  I know that&#8217;s inherently impractical, but it makes for a great mental model when whiteboarding a system.  And I think this gets near to the crux of my unease at the new name.  I think of a hexagonal architecture as a whole-system view, whereas PortsAndAdapters seems to look only at the system&#8217;s connections with the physical world.  The key, for me, is the symmetry, and the consequent removal of the constraints of the layered model.  I don&#8217;t care about the Ports; I&#8217;m interested instead in the central core where the knowledge lives, and the ability to interact with that core in flexible ways.  To me, hexagonal architecture is all about <strong>inner</strong> and <strong>outer</strong>, <strong>core</strong> and <strong>periphery</strong>, <strong>business knowledge</strong> and <strong>interfaces</strong>.</p>
<p>Why so much about just a name?  After all, it&#8217;s clear that neither name comes close to expressing the above&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[exceptions considered harmful]]></title>
<link>http://silkandspinach.net/2005/06/14/exceptions-considered-harmful/</link>
<pubDate>Tue, 14 Jun 2005 15:33:52 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2005/06/14/exceptions-considered-harmful/</guid>
<description><![CDATA[I like simple rules of thumb that will help developers create better, more adaptable designs. So her]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I like simple rules of thumb that will help developers create better, more adaptable designs.  So here&#8217;s another:  <strong>Never throw an exception.  And if someone throws one at you, catch it immediately and don&#8217;t pass it on.</strong></p>
<p>Why?  Aren&#8217;t exceptions one of the mainstays of modern programming?  Joel Spolsky outlines <a href="http://www.joelonsoftware.com/items/2003/10/13.html">the basic arguments against throwing exceptions</a>:</p>
<blockquote><p> &#8220;&#8230;I consider exceptions to be no better than &#8220;goto&#8217;s&#8221;, considered harmful since the 1960s, in that they create an abrupt jump from one point of code to another. In fact they are significantly worse than goto&#8217;s&#8230;&#8221;</p></blockquote>
<p>But then he goes on to give advice that I consider questionable at best, by suggesting that you catch exceptions quickly and convert them into return codes.  I agree that they should be caught at the earliest possible moment, but I disagree with converting them into return codes.  Because although that certainly makes the mechanism visible to the reader of the code, it still represents strong coupling where there should be none.  The caller &#8211; or someone further back along the call stack &#8211; has to know about, and take action in response to, someone else&#8217;s problem.  It seems to me that such coupling violates the pragmatic programmers&#8217; <a href="http://www.pragmaticprogrammer.com/ppllc/papers/1998_05.html">tell don&#8217;t ask</a> principle.<br />
<!--more--><br />
So what can we do when someone throws an exception at us?  To avoid strong coupling between parts of the system we shouldn&#8217;t inform the caller that we had a problem.  Instead, the object that catches the exception should set its own state such that it will answer future messages in the light of the problem that occurred.  (In particular, the <strong>NullObject</strong> or <a href="http://c2.com/cgi/wiki?SpecialCase">SpecialCase</a> pattern is useful here.)</p>
<p>For example, suppose we have a system that uses an external search engine, displaying the results on a GUI.  And suppose that the API to the search engine throws an exception if the engine cannot be contacted &#8211; for example if the network connection is not available.  If this occurs, we wish the GUI to display an error message instead of the search results.  The above argument states that we shouldn&#8217;t put a <code>try-catch</code> block in the GUI, with the catch part containing the code to display the error.  Instead, the <code>SearchResult</code> object returned by the engine could be special, having internal state that accords with the failure.  Further, the tell-don&#8217;t-ask rule tells us we still shouldn&#8217;t query the <code>SearchResult</code>&#8217;s state in order to discover what to display.  Instead the GUI could <em>tell</em> the object to display itself.  Then a normal <code>SearchResult</code> object would display a table of results, while a special <code>SearchResult</code> object would display an appropriate error message.</p>
<p>Finally, note that the above also has implications for hexagonal architectures.  The only code in our system that is permitted to throw exceptions is now the APIs we use.  And the adapters that connect us to those APIs must catch any exceptions immediately, before they can propagate up into the inner hexagon where the domain and applicationm objects live.  The presence of try-catch blocks is therefore yet another difference in code style between the inner and outer hexagons.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[databases as life-support for domain objects]]></title>
<link>http://silkandspinach.net/2005/05/23/databases-as-life-support-for-domain-objects/</link>
<pubDate>Mon, 23 May 2005 17:04:51 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2005/05/23/databases-as-life-support-for-domain-objects/</guid>
<description><![CDATA[In his article Domain-Centric Programming J.B.Rainsberger tells a very nice story about how a projec]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In his article <a href="http://www.stickyminds.com/BetterSoftware/magazine.asp?fn=cifea&#38;ac=167">Domain-Centric Programming</a> J.B.Rainsberger tells a very nice story about how a project was improved by leaving the database development to the very last.</p>
<blockquote><p>&#8220;The last thing I did was to build a simple, four-table database schema and a small component that read from and wrote to the live database. Since I had practiced test-driven development &#8230; I had high confidence that I had implemented everything correctly. Since I had focused on the domain, rather than the database, I was even more confident that I had gotten the database right the first time.&#8221;</p></blockquote>
<p>(Thanks to Brian Marick for bringing the article to light, via the agile-testing group on Yahoo.)</p>
<p>By pure coincidence I&#8217;ve been telling very similar stories on a project I&#8217;m coaching at the moment.  We&#8217;re currently investigating approaches for the architecture of a new product line, and the group thinks that we might gain a lot by thinking in terms of a <a href="http://silkandspinach.wordpress.com/2004/07/13/hexagonal-architecture/">hexagonal architecture</a>.  During the last couple of weeks I&#8217;ve been thinking a bit more about such models, and I&#8217;ve come to a rather remarkable conclusion:  the database is <em>not</em> on the outside.  I now believe that the database is merely one of the technologies that together create the nutrient environment supporting the objects in the middle hexagon.<br />
<!--more--><br />
As J.B. said in his article, the database exists solely to bring persistent state to the domain (and application) objects.  Logically, then, it isn&#8217;t part of the &#8220;outside world&#8221;, to be connected by an adapter to the domain objects.  Instead, it&#8217;s part of the memory model in which the action takes place.  It&#8217;s one of the tools used to build the middle hexagon.  (I feel instinctively that the adapters shouldn&#8217;t have persistent state.  I&#8217;m probably wrong.)</p>
<p>Think of the domain objects as being &#8220;always there&#8221;.  When the adapters are talking to them, they&#8217;re in primary memory.  But when no-one is interested in them they may be archived out to secondary storage.  If someone needs one of them again, the middle hexagon arranges to &#8220;re-inflate&#8221; any archived objects.  This may show up as a slight delay &#8211; just as when you re-access an application that was paged out by your operating system.  The delay in opening a connection to any particular domain object depends on &#8220;how far away&#8221; it has been archived:  instantaneous when it&#8217;s active in memory, slightly longer when it has to be awakened from a database, longer still if it was archived to an old guy in a back room with a quill pen.  Whatever the technology used, though, it&#8217;s still just technology.  Still nothing more than the life-support environment in which the domain objects ply their business.</p>
<p>I discovered during our workshops last week that this is a huge topic.  I&#8217;ve only scratched the surface here, and I haven&#8217;t had the time to work through all of the consequences in practice.  But the ideas do seem to hang together, at least in this person&#8217;s head if nowhere else.  More to come, I expect&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[hexagonal soup]]></title>
<link>http://silkandspinach.net/2004/07/16/hexagonal-soup/</link>
<pubDate>Fri, 16 Jul 2004 16:07:50 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2004/07/16/hexagonal-soup/</guid>
<description><![CDATA[So if we can completely remove all duplicate conditionals, what will our code be like? Well the only]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>So if we can completely remove all <a href="http://silkandspinach.wordpress.com/2004/07/16/if/">duplicate conditionals</a>, what will our code be like?  Well the only remaining conditionals (<code>if</code> statements, <code>switch</code> statements etc) will be those that test something that&#8217;s set or defined outside of the system, ie. something that&#8217;s part of the runtime environment.  The two or more code branches selected by such a conditional will tend to consist entirely of the creation/execution of different sets of objects.  Each of these sets of objects must by definition &#8216;know&#8217; what event or state occurred, probably because it was passed parameters that embody the environment&#8217;s state or prior decisions.  And so within those invoked object sets there need be no conditional code at all.</p>
<p>This situation now dovetails neatly with Alistair Cockburn&#8217;s <a href="http://silkandspinach.wordpress.com/2004/07/13/hexagonal-architecture/">hexagonal architecture</a> pattern&#8230;</p>
<p>The conditional statements themselves, because they form part of the response of the system to it&#8217;s environment, should be in the outer hexagon, in what Alistair calls the &#8216;transformers&#8217; (and what I tend to call &#8216;adapters&#8217;).  And if there really is no duplication of conditional statements, the inner hexagon (ie. the application and domain objects in Alistair&#8217;s model) will contain no conditional logic whatever!  The inner hexagon is purely a soup of objects waiting to be invoked and parameterised in response to external stimuli.</p>
<p>So here&#8217;s a very simple rule you can apply to any system:  Look at every conditional statement and check that it&#8217;s sitting in one of the adaptors connecting to the environment.  If it isn&#8217;t it must be duplicating some knowledge that the system already holds elsewhere&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[reflections on xpdays benelux 2005]]></title>
<link>http://silkandspinach.net/2005/11/21/reflections-on-xpdays-benelux-2005/</link>
<pubDate>Mon, 21 Nov 2005 15:06:24 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2005/11/21/reflections-on-xpdays-benelux-2005/</guid>
<description><![CDATA[Last week I spent an enjoyable day at XPdays Benelux in Rotterdam. I ran a couple of sessions, atten]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Last week I spent an enjoyable day at <a href="http://xpday.net/">XPdays Benelux</a> in Rotterdam.  I ran a couple of sessions, attended a couple more, and met up with friends old and new.  Here are brief recollections of the highlights in my day&#8230;</p>
<p>The day began with every presenter offering a 1-minute sales pitch for their session.  I got to do two: one for <em>Hexagonal Architecture</em> and one for <em>Jidoka</em>.  A minute is longer than you&#8217;d think, and I&#8217;d guess that most of the pitches were over inside twenty seconds.  I decided to be a little different, so I had everyone stand on one leg &#8211; hopefully to demonstrate that the standard layered architecture model compromises agility&#8230;<br />
<!--more--><br />
I then went to the first half of Joseph Pelrine&#8217;s <a href="http://www.xpday.net/Xpday2005/MakingSense.html">Cynefin workshop</a>.  I had to leave at the midpoint, due to the timing of my Hexagonal session; but what I saw in the first half intrigued me.  I regret having paid little attention to Cynefin thus far, although after Joseph&#8217;s introduction I plan to catch up as quickly as I can.</p>
<p><a href="http://www.xpday.net/Xpday2005/HexagonalArchitecture.html">Hexagonal architecture</a> was a late substitution after another session dropped out.  I&#8217;ve done a poor job at selling this topic to conferences: reviewers commented repeatedly &#8211; and correctly &#8211; that I failed to explain its connection with agile development.  Consequently this is the only conference that has accepted the session, and so I wasn&#8217;t sure what to expect on its first outing.  So earlier, while thinking about what to say for my 1-minute sales pitch, I had tried to work out why I instinctively feel there&#8217;s a connection to be made.  I had concluded that the layered architecture model makes it harder to design adaptable systems, simply because we tend to think of things at the bottom of a stack as being harder to remove or replace (hence asking evefryone to stand on one leg).  So the session turned into a lively debate about the power of metaphors in shaping our unconscious thinking, together with interesting discussions about the role of databases, and the use of throw-away user interfaces in the early stages of developing the domain objects.  I felt it went well, due to the range of opinion in the group and everyone&#8217;s enthusiasm for engaged debate.</p>
<p>At lunch, the refreshment on offer was milk.  Very Dutch, and a nice touch.</p>
<p>Then it was on to Christophe and Emmanuel&#8217;s <a href="http://www.xpday.net/Xpday2005/CodersDojo.html">coder&#8217;s dojo</a>.  As with so many things, a coding dojo is something I&#8217;ve been meaning to experience for a long time; I wasn&#8217;t disappointed.  The first half of the session consisted of Christophe and Emmanuel running through a prepared <em>kata</em>, in which they had to develop a flight scheduling algorithm in Ruby.  The point here is that, although they had worked through the exercise together previously, the session wasn&#8217;t just a code walkthrough.  Instead, they wrote all code and tests from scratch, so that the audience was fully engaged in solving the problem together.  (In retrospect, the customer acceptance tests should perhaps have been expressed in prepared FIT tables.  Instead, they were developed &#8220;live&#8221; using RubyUnit, which confused the group into thinking in terms of unit tests and TDD too early in the process.)  After the tea-break the session switched to become a <em>randori</em>.  The group selected a problem from a shortlist of 4-5 &#8211; we chose conversion of Roman numerals into Arabic numbers &#8211; and developed a Ruby implementation test-first.  The catch is that each pair only gets 5 minutes at the keyboard; when time&#8217;s up, the driver exits, the co-pilot becomes driver, and a new co-pilot volunteers to step up out of the audience.  The session participants demonstrated a wide variety of approaches to TDD, including Microsoft&#8217;s &#8220;write all the tests up front&#8221;.  This somewhat derailed the flow, although much was accomplished in the time available.  I suspect that the dojo concept will work best when the group has time, over a number of sessions, to evolve a common style and approach &#8211; as the <a href="http://bossavit.com/dojo/">Paris dojo group</a> has done during the course of this year.</p>
<p>Finally, my second session of the day:  <a href="http://www.xpday.net/Xpday2005/JidokaInSoftware.html">jidoka</a>.  This topic has proved extremely popular; I&#8217;ve already run it for <a href="http://silkandspinach.net/2005/08/23/jidoka-at-agile-scotland/">AgileScotland</a>, and I&#8217;ll be running it again at XPday London and at SPA2006.  The beauty of the discussion format is that the session is never the same twice, and so it proved again here.  The AgileScotland group stuck very much with the themes of stopping the production line and root-cause analysis, while this Benelux crowd veered all over the place, finally settling on a lively debate about the use of weekly retrospectives to drive process evolution.  This was a big group, and with a fair amount of Devil&#8217;s Advocacy in some quarters we had a broad spread of informed opinion, and I enjoyed the session immensely.</p>
<p>Willem has posted <a href="http://ruminations.willemvandenende.com/rublog/rublog.cgi/BeingAgile/XPDayBeneluxPhotos.txl">photos</a> of the conference (including one showing me and the attendees standing on one leg!)</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[mocks and adapters]]></title>
<link>http://silkandspinach.net/2005/10/31/mocks-and-adapters/</link>
<pubDate>Mon, 31 Oct 2005 13:35:18 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2005/10/31/mocks-and-adapters/</guid>
<description><![CDATA[In A thought on mocking filesystems Brian Marick provides yet another reason to think in terms of a ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In <a href="http://www.testing.com/cgi-bin/blog/2005/10/30#mocking-filesystem">A thought on mocking filesystems</a> Brian Marick provides yet another reason to think in terms of a hexagonal architecture.  Discussing the writing of mock objects for huge components such as a filesystem, he writes:</p>
<blockquote><p>&#8220;So it seems to me that a project ought to write to the interface they wish they had (typically narrower than the real interface). They can use mocks that ape their interface, not the giant one. There will be adapters between their just-right interface and the giant interface. Those can be tested separately from the code that uses the interface.&#8221;</p></blockquote>
<p>Mocks/stubs and adapters are natural bedfellows, and definitely help to keep code clean and testable.  I once worked on a project in which the &#8220;filesystem&#8221; was a JNDI directory service.  And then later that was scrapped in favour of a plain old filesystem.  How I wish I had known about hexagonal architectures then, because it was a real nightmare to disentangle the JNDI dependencies from the rest of the system.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[sessions at XPday Benelux]]></title>
<link>http://silkandspinach.net/2005/09/21/sessions-at-xpday-benelux/</link>
<pubDate>Wed, 21 Sep 2005 11:19:30 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2005/09/21/sessions-at-xpday-benelux/</guid>
<description><![CDATA[My Jidoka and Hexagonal Architecture sessions have been accepted for XPday Benelux 2005 in Rotterdam]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>My <em>Jidoka</em> and <em>Hexagonal Architecture</em> sessions have been accepted for <a href="http://www.xpday.net/Xpday2005/Program.html">XPday Benelux 2005</a> in Rotterdam this November.  Looks like a great programme &#8211; shame I won&#8217;t be able to attend everything!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[pseudo-OO]]></title>
<link>http://silkandspinach.net/2005/05/20/pseudo-oo/</link>
<pubDate>Fri, 20 May 2005 13:58:03 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2005/05/20/pseudo-oo/</guid>
<description><![CDATA[In Pseudo-OO Design Dadi Ingolfsson talks about that all-too-common phenomenon &#8211; a design in w]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In <a href="http://spaces.msn.com/members/blubberplinth/Blog/cns!1ph1IFVB92jPeGXHEH2mc2qw!111.entry" title="Pseudo-OO Design">Pseudo-OO Design</a> Dadi Ingolfsson talks about that all-too-common phenomenon &#8211; a design in which the code and the data are separate.</p>
<blockquote><p>&#8220;This relates to the Microsoft-style of a DAL (Data Access Layer), a BLL (Business Logic Layer) and a UI, where the data that travels through the layers might be, for instance, dumb Customer objects or DataSet objects. The objects in these different layers are very procedural in nature as they usually only operate on data in objects that are sent to them rather than the data being their own. It´s what Fowler called an Anemic Domain Model. This is not OO design even though many programmers seem to think code is OO if it has classes and objects.&#8221;</p></blockquote>
<p>By coincidence, this week I found myself workshopping agile programming with a team whose legacy C++ system is just like this.  My approach to gradually improving the situation is to look for instances of the <a href="http://c2.com/cgi/wiki?FeatureEnvy">feature envy</a> smell.  Bit by bit, as we find each of these smells, we move the code into the objects where it belongs.  Bit by bit, encapsulation improves.  Bit by bit, the domain model emerges in the code.  And very often, as we introduce abstractions to improve testability, bit by bit a <a href="http://silkandspinach.net/2004/07/13/hexagonal-architecture/">hexagonal architecture</a> emerges too.</p>
<p>Why is this important?  Why is it bad to separate the code from the data?  Because it stops the code changing at the pace of the business.  Distributed behaviour and state mean that each piece of business knowledge is also distributed throughout the system.  Which means that any new or changed requirement will cost more to implement.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[the middle hexagon should be independent of the adapters]]></title>
<link>http://silkandspinach.net/2005/03/22/the-middle-hexagon-should-be-independent-of-the-adapters/</link>
<pubDate>Tue, 22 Mar 2005 10:22:32 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2005/03/22/the-middle-hexagon-should-be-independent-of-the-adapters/</guid>
<description><![CDATA[The standard three- or four-layer models of application architecture seem to dictate the direction o]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The standard three- or four-layer models of application architecture seem to dictate the direction of the dependencies between the various &#8220;kinds&#8221; of object in the system:  The UI depends on the application layer, because the UI &#8220;drives&#8221; what happens &#8220;below&#8221;.  The application layer depends on the business objects, which do all the domain-specific things.  The business objects use (and hence depend on) the persistence layer and comms layer, both of which in turn use and depend on external APIs.  It is perfectly natural to read a layered model in this way &#8211; indeed, that was its purpose.</p>
<p align="center"> <tt><br />
ui ---&#62; application ---&#62; domain ---&#62; (persistence, comms)<br />
</tt></p>
<p>And it is this very interpretation that has made so many applications difficult or impossible to test.  Each of those perceived dependencies ends up enshrined in the code structure, and by stealth the design has cast in concrete the layered model.  At which point someone like me comes along an exhorts the developers to improve their test coverage.  I&#8217;m told:  &#8220;We tried that, but it takes too long to manage the Oracle testdata we&#8217;d need to test the GUI,&#8221; or something similar.  Or the business decides to switch to a new database or enterprise comms architecture, requiring huge swathes of business logic to be re-engineered.</p>
<p>Alistair Cockburn&#8217;s <a href="http://c2.com/cgi/wiki/?HexagonalArchitecture">hexagonal architecture</a> model introduces an axis of symmetry that can help us see how to solve these kinds of problem:<br />
<!--more--><br />
Instead of the above-and-below of the layered model, we look at exactly the same application (and exactly the same code) using an inside-outside model.  The domain objects sit in the middle, and are connected to the real world by what I call <em>Adapters</em> &#8211; a GUI, CGI scripts, a command-line, hardware controllers, a print spooler, etc.  Each adaptor connects the domain objects to a different part of the &#8216;real&#8217; world.</p>
<p>So let&#8217;s look at our untestable or non-portable application from the &#8220;hexagonal&#8221; point of view.  (Remember, we&#8217;re still talking about the same codebase here:  only our discursive model has changed.)  The dependencies that have made testing so difficult, and which exist in response to a naive interpretation of the layered model, clearly violate the symmetry of the hexagonal model.</p>
<p align="center"> <tt><br />
ui ---&#62; (app, domain) ---&#62; services<br />
</tt></p>
<p>If we wish to be able to easily port the application to use different services, we&#8217;ll need to be able to easily replace the adapters that connect us to those services.</p>
<p align="center"> <tt><br />
ui ---&#62; (app, domain) ---&#62; new services<br />
</tt></p>
<p>And if we wish to test the domain objects independently from the hardware, we&#8217;ll need to be able to replace various adapters with stubs, shunts or Mock Objects.</p>
<p align="center"> <tt><br />
fit ---&#62; (app, domain) ---&#62; mock services<br />
</tt></p>
<p>We can&#8217;t do this currently because the design violates Bertrand Meyer&#8217;s Open-Closed Principle (&#8220;<em>A system should be open to extension, but closed to modification</em>&#8220;).  To solve the problem we need to use Uncle Bob&#8217;s <a href="http://www.objectmentor.com/mentoring/OOPrinciples">Dependency Inversion Principle</a>:  We introduce abstractions into the middle hexagon, such that the current adapters implement those abstractions.</p>
<p align="center"> <tt><br />
ui ---&#62; (app, domain ---&#62; abstraction) &#60;--- service </tt></p>
<p>Symmetry is now restored:  every adapter depends on the middle hexagon, and the middle hexagon (our domain objects) is independent of the physical context in which it is used.</p>
<p align="center"> <tt><br />
adapter ---&#62; middle &#60;--- adapter </tt></p>
<p>Now we can more easily see how to peel off any adapter(s) we wish and replace them with mock objects or different services.  The adapter/middle axis of symmetry is the key ingredient in improving both testability and portability of enterprise applications.</p>
<p><em>Update, 16 aug 05</em><br />
In <a href="http://www.williamcaputo.com/archives/000225.html">TDD Pattern: Do not cross boundaries Revisited</a> William Caputo provides both UML and C# code to illustrate his design pattern for removing the dependency on an adapter.  This follows his <a href="http://www.williamcaputo.com/archives/000019.html">earlier post</a>, which argues that test-driven coding would naturally tend to produce the de-coupled form of the design.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[hexagonal architecture]]></title>
<link>http://silkandspinach.net/2004/07/13/hexagonal-architecture/</link>
<pubDate>Tue, 13 Jul 2004 11:21:11 +0000</pubDate>
<dc:creator>Kevin Rutherford</dc:creator>
<guid>http://silkandspinach.net/2004/07/13/hexagonal-architecture/</guid>
<description><![CDATA[Ever since I heard of it (around 1998 or so) I&#8217;ve been trying to persuade people to think in t]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Ever since I heard of it (around 1998 or so) I&#8217;ve been trying to persuade people to think in terms of Alistair Cockburn&#8217;s <a href="http://c2.com/cgi/wiki?HexagonalArchitecture">hexagonal architecture</a> model.  To me, it takes away so many of the pointless debates, and makes modelling and developing any new system so much simpler.  Thanks Alistair!</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
