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

<channel>
	<title>The Iterator &#187; domain</title>
	<atom:link href="http://theiterator.com/tag/domain/feed/" rel="self" type="application/rss+xml" />
	<link>http://theiterator.com</link>
	<description>This is my blog. There are many like it, but this one is mine.</description>
	<lastBuildDate>Thu, 10 Dec 2009 06:13:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Semantic domain modeling</title>
		<link>http://theiterator.com/2009/02/semantic-domain-modeling/</link>
		<comments>http://theiterator.com/2009/02/semantic-domain-modeling/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 18:35:58 +0000</pubDate>
		<dc:creator>theiterator</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[domain driven design]]></category>
		<category><![CDATA[modeling]]></category>
		<category><![CDATA[semantics]]></category>

		<guid isPermaLink="false">http://theiterator.com/?p=71</guid>
		<description><![CDATA[Coding, after all, is just writing.
&#8211; Jeff Atwood
Yup. Jeff covers some essential aspects of the curious relationship between writing and coding in his post, focusing on the perspective of style and readability. I&#8217;ll now give a shot on extending on that topic. I&#8217;ve been kicking around the subject of domain modeling in my post drafts [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Coding, after all, is just writing.</p></blockquote>
<p>&#8211; <a href="http://www.codinghorror.com/blog/archives/001184.html">Jeff Atwood</a></p>
<p>Yup. Jeff covers some essential aspects of the curious <strong>relationship between writing and coding</strong> in his post, focusing on the perspective of style and readability. I&#8217;ll now give a shot on extending on that topic. I&#8217;ve been kicking around the subject of domain modeling in my post drafts bin for quite a while, not knowing how to present it. Today it hit me during a sprint review at a client. There is nothing revolutionary here. It&#8217;s all <strong>basic domain modeling and design patterns</strong>, but viewed from a different angle.</p>
<p>Numerous are the times I have come across inconsistencies in domain models due to misunderstandings in the development process from the actual domain to object model. I&#8217;m sure you have too, and this is nothing new under the sun, and to some degree somewhat unavoidable. Perhaps you&#8217;ve also seen <strong>objects used for something they weren&#8217;t meant and designed for</strong>. This could be due to architectural shortcomings, laziness or just plain ignorance.</p>
<p>As a harsh example, I&#8217;ll describe a case of architectural shortcomings that forced me to do an ugly hack and thus leverage a wrong object for the job at hand. The GUI components of the application featured a parameter-generated form &#8211; dubiously titled ViewForm -  for performing complex database queries to ultimately retrieve an entity to open into another form for modification.</p>
<p>First of all, naming the form ViewForm is just a cracker-jack job at crafting an <a href="http://domaindrivendesign.org/discussion/messageboardarchive/UbiquitousLanguage.html">ubiquitous language</a>. It&#8217;s a form that views stuff. You must be shitting me. How about SearchForm? After all, it&#8217;s a form that searches stuff. Infrastructural domain objects should be named with equal care as the ones in the business end that have taken years and years to refine into concise,  yet semantically clean terms. Ultimately the distilled purpose of the ViewForm component is to search stuff, so I&#8217;ll assume from now on that this naming quirk hadn&#8217;t been there.</p>
<p>The hack in question? I was asked to implement a search form that queried two separate tables &#8211; <strong>import and export shipments</strong> &#8211; and opened a different form depending on the type of consignment the user double-clicked on. I ended up creating a dummy form with absolutely no visual components on it, and some code in the Form_Load (or such, luckily can&#8217;t remember a thing of the VB6 API&#8217;s) event handler that figured out which of the two consignments it was, opened the corresponding form and closed the dummy one.</p>
<p>The said form performed nicely enough in the job of querying, and being configurable and all that. The problem, however, presented itself when a series of domain modeling mistakes met, reaching <strong>a critical mass of code smell</strong>. Following are the essential shortcomings that led me to produce probably the ugliest hack I&#8217;ve ever had the balls to ship:</p>
<ol>
<li>We&#8217;re talking about ERP-style software here, and thus <strong>object-oriented programming should be a given</strong>. No objects here, other than infrastructural ones, courtesy of VB6 (Form, Control etc). This results in aforementioned search form querying for database rows instead of entities. So no strong typing to be relied on. That also means that refactoring the query form configuration model would&#8217;ve been a tedious exercise of implement-and-wait-for-the-bug-reports.</li>
<li>When the data schema is modeled merely as database tables and a bunch of functions scattered across random forms all over the place, the domain model easily scatters into a bit of a disorganized mush. In this case, the business requirements dictated that the system should handle import and export shipments, thus the developer creates <em>separate tables for them</em> without stopping for a minute to ponder the <em>semantics</em> of the two. <strong>A shipment is a shipment,</strong> regardless of its direction, I dare to assert.</li>
<li>The configuration data schema for the query form was modeled so that there was a query form definition and it had a bunch of associated column definitions. The gotcha was that the query form definition held the name of the <em>form</em> that would be opened when a user double-clicked a row in the results grid. The semantics of a query form per se come into question here &#8211; is query form a query form or a query-and-open-another-form form &#8211; but mostly in the sense of <strong>separation of concern</strong>.</li>
</ol>
<p>Though all of the aforementioned architectural turds play an important role, the third one is the most essential one in this particular case. The coding-as-writing analogy plays out here in the sense that <strong>having a semantically clean ubiquitous language paves the way for clean and pragmatic separation of concern</strong>. If the domain model defines a search form, you implement a search form that knows about searching for stuff, and that maybe something needs to be done with the stuff that it finds: something, but not what exactly.</p>
<p>Rather than referring to an individual form to open, the search definition should&#8217;ve pointed to a <a href="http://en.wikipedia.org/wiki/Strategy_pattern">strategy</a> object that would&#8217;ve done whatever it wanted with the row of information: figure out a form to open or perhaps perform some other processing on the record. Now I had to emulate that behavior using a Form object to do something it&#8217;s not designed nor meant for.</p>
<p>Moving on to unfolding screwup number two. I once tried fishing out a reason for the crowbar-separation of the two shipment directions and got something along the lines of &#8220;well it&#8217;s because they are a totally different business&#8221;. Well humm righty-o, but isn&#8217;t a shipment still a bunch of goods that is going from one place to another, results in costs to an array of involved parties and is dictated by a set of legislation, contracts and whatnot?</p>
<p>An imported shipment might hold some information that an exported one doesn&#8217;t and vice versa, but <strong>object-oriented programming provides inheritance and relational databases provides relationships for just that</strong>. Eventually both of the shipment types still need to be treated as equals, just like what happened here. Another highly probable case would be a statistical report on import-to-export ratios.</p>
<p>The key point I&#8217;m trying to make here, is that, if the <a href="http://domaindrivendesign.org/discussion/messageboardarchive/UbiquitousLanguage.html">ubiquitous language</a> has been crafted carefully, <strong>evaluating semantics provides a logical and robust back bone for designing the object model</strong>. Now that I think of it, I can&#8217;t see another way to really model a domain. Yet every day I witness failures &#8211; albeit smallers ones &#8211; in modeling that would&#8217;ve been solved by really grinding the terms used to describe the objects.</p>
<p>When an ubiquitous language starts to take shape, go through the terms described and really chew them fine. <strong>If the term isn&#8217;t concise or unambiguous enough, finetune it until it is</strong>. Then use that information to form a pragmatic object model that separates concerns logically.</p>
<p class="bookmark-me"><a title="technorati.com" href="http://www.technorati.com/faves?add=http%3A%2F%2Ftheiterator.com%2F2009%2F02%2Fsemantic-domain-modeling%2F"><img src="http://theiterator.com/wp-content/plugins/bookmark-me/images/technorati.png" style="margin:0;border:0;padding:0" alt="bookmark"/></a> <a title="del.icio.us" href="http://del.icio.us/post?url=http%3A%2F%2Ftheiterator.com%2F2009%2F02%2Fsemantic-domain-modeling%2F&amp;title=Semantic+domain+modeling"><img src="http://theiterator.com/wp-content/plugins/bookmark-me/images/delicious.png" style="margin:0;border:0;padding:0" alt="bookmark"/></a> <a title="stumbleupon.com" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftheiterator.com%2F2009%2F02%2Fsemantic-domain-modeling%2F&amp;title=Semantic+domain+modeling"><img src="http://theiterator.com/wp-content/plugins/bookmark-me/images/stumbleupon.png" style="margin:0;border:0;padding:0" alt="bookmark"/></a> <a title="digg.com" href="http://digg.com/submit?url=http%3A%2F%2Ftheiterator.com%2F2009%2F02%2Fsemantic-domain-modeling%2F&amp;title=Semantic+domain+modeling"><img src="http://theiterator.com/wp-content/plugins/bookmark-me/images/digg.png" style="margin:0;border:0;padding:0" alt="bookmark"/></a> <a title="www.facebook.com" href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftheiterator.com%2F2009%2F02%2Fsemantic-domain-modeling%2F&amp;t=Semantic+domain+modeling"><img src="http://theiterator.com/wp-content/plugins/bookmark-me/images/facebook.png" style="margin:0;border:0;padding:0" alt="bookmark"/></a> <a title="reddit.com" href="http://reddit.com/submit?url=http%3A%2F%2Ftheiterator.com%2F2009%2F02%2Fsemantic-domain-modeling%2F&amp;title=Semantic+domain+modeling"><img src="http://theiterator.com/wp-content/plugins/bookmark-me/images/reddit.png" style="margin:0;border:0;padding:0" alt="bookmark"/></a> <a title="twitthis.com" href="http://twitthis.com/twit?url=http%3A%2F%2Ftheiterator.com%2F2009%2F02%2Fsemantic-domain-modeling%2F&amp;title=Semantic+domain+modeling"><img src="http://theiterator.com/wp-content/plugins/bookmark-me/images/twitter.png" style="margin:0;border:0;padding:0" alt="bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://theiterator.com/2009/02/semantic-domain-modeling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
