<?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>Crafting software&#187; Architecture</title>
	<atom:link href="http://davidlaing.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidlaing.com</link>
	<description>David Laing&#039;s thoughts on software development</description>
	<lastBuildDate>Wed, 01 Feb 2012 11:02:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>DTOs: To Flatten Or Not To Flatten?</title>
		<link>http://davidlaing.com/2010/04/20/dtos-to-flatten-or-not-to-flatten/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dtos-to-flatten-or-not-to-flatten</link>
		<comments>http://davidlaing.com/2010/04/20/dtos-to-flatten-or-not-to-flatten/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 06:58:39 +0000</pubDate>
		<dc:creator>mrdavidlaing</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Software Craftmanship]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[design_patterns]]></category>
		<category><![CDATA[dtos]]></category>

		<guid isPermaLink="false">http://davidlaing.com/?p=200</guid>
		<description><![CDATA[that is the question&#8230; I&#8217;m busy working on a JSON based API with client libraries in Flex, C# and Javascript (and eventually iPhone, JavaFX etc). One of the things the API deals with is the concept of a Market. Markets have a number of properties that &#8220;belong&#8221; to them, simplistically things like MarketId and Name. [...]]]></description>
			<content:encoded><![CDATA[<p>that is the question&#8230;</p>
<p>I&#8217;m busy working on a JSON based API with client libraries in Flex, C# and Javascript (and eventually iPhone, JavaFX etc).</p>
<p>One of the things the API deals with is the concept of a Market.  Markets have a number of properties that &#8220;belong&#8221; to them, simplistically things like MarketId and Name.</p>
<pre class="brush: csharp; title: ; notranslate">
public class Market
{
    public int MarketId {get; set;}
    public string Name {get; set;}
}
</pre>
<p>However, I can see that in using a list of markets, its going to be useful to know related data about the market for things like sorting. For example, when showing a list of markets I&#8217;d like to know the volume traded in the last day so I can colour them differently.  Or the price change in the last hour etc.</p>
<p>DTO wise, there seem to be several options.</p>
<ol>
<li>
<h4>Flattening with &#8220;nulls&#8221;</h4>
<pre class="brush: csharp; title: ; notranslate">
public class Market
{
    public int MarketId {get; set;}
    public string Name {get; set;}
    public decimal? VolumeInLastDay {get; set;}
    public decimal? PriceDeltaLastHour {get; set;}
}
</pre>
<p>It seems that over time this approach will lead to very &#8220;messy&#8221; DTOs where you&#8217;re forced to do a lot of &#8220;isNull&#8221; style checking before attempting to display things.
</li>
<li>
<h4>Multiple specific MarketWithXYZ DTOS</h4>
<pre class="brush: csharp; title: ; notranslate">
public class MarketWithVolume: Market
{
    public decimal VolumeInLastDay {get; set;}
}

public class MarketWithPriceDelta: Market
{
    public decimal PriceDeltaLastHour {get; set;}
}

public class MarketWithVolumeAndPriceDelta: MarketWithVolume
{
    public decimal? PriceDeltaLastHour {get; set;}
}
</pre>
<p>An explosion of DTOs, but at least you know exactly what data you&#8217;ve got at any instance
</li>
<li>
<h4>Property Bags</h4>
<pre class="brush: csharp; title: ; notranslate">
public class Market
{
    public int MarketId {get; set;}
    public string Name {get; set;}
    public Hashtable RelatedData {get; set;}
}

decimal delta = Market.RelatedData[&quot;PriceDeltaLastHour &quot;];
</pre>
<p>In a way this feels even worse than having multiple null attributes; especially for someone new to the API because you won&#8217;t know until run time which data is available.
</li>
</ol>
<p>How have you approached this problem in the past?  What works, and what doesn&#8217;t?  Comments much appreciated.</p>
<p><strong>Update</strong></p>
<ul>
<li>Reduced duplication in Multiple specific option using inheritance</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://davidlaing.com/2010/04/20/dtos-to-flatten-or-not-to-flatten/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Utils anti-pattern &amp; AutoMapper</title>
		<link>http://davidlaing.com/2009/06/02/utils-anti-pattern-automapper/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=utils-anti-pattern-automapper</link>
		<comments>http://davidlaing.com/2009/06/02/utils-anti-pattern-automapper/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 09:18:41 +0000</pubDate>
		<dc:creator>mrdavidlaing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Code smells]]></category>
		<category><![CDATA[automapper]]></category>
		<category><![CDATA[utils-anti-pattern]]></category>

		<guid isPermaLink="false">http://davidlaing.com/?p=190</guid>
		<description><![CDATA[These are more for my reference purposes &#8211; hopefully you&#8217;ll find them useful: If you&#8217;re about to name a class **Util; think harder &#8211; there is a better name that discribes what that class is for: Chriss Missal has some advice for you Faced with the prospect of heaps of left hand side =&#62; right [...]]]></description>
			<content:encoded><![CDATA[<p>These are more for my reference purposes &#8211; hopefully you&#8217;ll find them useful:</p>
<p>If you&#8217;re about to name a class **Util; think harder &#8211; there is a better name that discribes what that class is for:<br />
<a href="http://www.lostechies.com/blogs/chrismissal/archive/2009/06/01/anti-patterns-and-worst-practices-utils-class.aspx">Chriss Missal has some advice for you</a></p>
<p>Faced with the prospect of heaps of left hand side =&gt; right hand side code in your DTO of anti-corruption layer?  Consider <a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/01/22/automapper-the-object-object-mapper.aspx">Jimmy Bogard&#8217;s Automapper</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidlaing.com/2009/06/02/utils-anti-pattern-automapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Simplest thing that could Possibly work</title>
		<link>http://davidlaing.com/2008/06/27/the-simplest-thing-that-could-possibly-work/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-simplest-thing-that-could-possibly-work</link>
		<comments>http://davidlaing.com/2008/06/27/the-simplest-thing-that-could-possibly-work/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 12:57:26 +0000</pubDate>
		<dc:creator>mrdavidlaing</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://davidlaing.com/?p=67</guid>
		<description><![CDATA[Jay has a good discussion concerning the design dilemma we often face considering the &#8220;simplest thing that could possible work&#8221;. Is it appropriate to implement a simple half baked solution that we know we will throw away as requirements become more defined? Or should we start out with a more complex pattern that will give [...]]]></description>
			<content:encoded><![CDATA[<p>Jay has a good discussion concerning the design dilemma we often face considering the &#8220;simplest thing that could possible work&#8221;.  Is it appropriate to implement a simple half baked solution that we know we will throw away as requirements become more defined?  Or should we start out with a more complex pattern that will give us more flexibility?</p>
<p><a href="http://blog.jayfields.com/2008/06/simplest-thing-that-could-possibly-work.html">http://blog.jayfields.com/2008/06/simplest-thing-that-could-possibly-work.html</a></p>
<p>Jay concludes that you can&#8217;t decide which pattern will give you the right flexibility until you have more requirements.  So, rather than potentially implement the <strong>wrong</strong> complex solution, just treat the temporary solution as part of the learning process.</p>
<p>I agree.  Like optimising, you need to know the precise requirements before you can choose the right pattern.</p>
<p>Throw away code isn’t wasted; rather its used like scrap paper in the learning process.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlaing.com/2008/06/27/the-simplest-thing-that-could-possibly-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

