<?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>Sarah Taraporewalla's Technical Ramblings &#187; Design</title>
	<atom:link href="http://sarahtaraporewalla.com/thoughts/category/design/feed/" rel="self" type="application/rss+xml" />
	<link>http://sarahtaraporewalla.com/thoughts</link>
	<description></description>
	<lastBuildDate>Sun, 31 Jan 2010 22:03:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Working With Integration Points: Simulators</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/working-with-integration-points-simulators/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/design/working-with-integration-points-simulators/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 22:03:10 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=303</guid>
		<description><![CDATA[In my last post about working with integration points I described how I use anti-corruption layers (wrappers) to hide away any warts of the integration point. In this post, I will explain how I used these wrappers to help develop against an integration point which was also under development.

The problem with two systems being developed [...]]]></description>
			<content:encoded><![CDATA[<div>In my last post about <a href="http://sarahtaraporewalla.com/thoughts/design/working-with-integration-points-anticorruption-layer/">working with integration points</a> I described how I use anti-corruption layers (wrappers) to hide away any warts of the integration point. In this post, I will explain how I used these wrappers to help develop against an integration point which was also under development.</div>
<div></div>
<div>The problem with two systems being developed concurrently is that it is rare that they are developed at the same rates, or even in the same priority. That means that the consumer can often be left waiting for functionality to be delivered before they can start developing against it. And that assumes that it all works (not a wise assumption if my previous projects are anything to go by).</div>
<div></div>
<div>There is another way however &#8211; by using simulators to develop against. The simulators can be as sophisticated as you need them be &#8211; either returning pre-canned values or randomising the responses. They can live in-memory or they can be across the wire depending on what your focus is. Or have both types and simulate less and less and you move through the CI pipeline. An in-memory simulator can replace your wrapper easily using your DI container (it also helps draw the distinction between logic for the business service and logic for the wrapper).</div>
<div><a href="http://sarahtaraporewalla.com/thoughts/wp-content/uploads/2010/01/simulators.jpg"><img class="aligncenter size-medium wp-image-302" title="simulators" src="http://sarahtaraporewalla.com/thoughts/wp-content/uploads/2010/01/simulators-300x201.jpg" alt="" width="300" height="201" /></a></div>
<div></div>
<div>The main importance of simulators is that they let you develop independently of other teams. An added benefit is that they help you define a consumer-driven contract (if you are the consumer). You can also use the simulators to help identify problems with the system &#8211; if it works against the simulator and not against the real integration system, then there is a problem with the integration system. If there is a problem even with the simulator then there is a problem in your system. If it works against the in-memory simulator but not against the simulator across the wire, then your problem lies somewhere on the wire.</div>
<div></div>
<div>Simulators can really help you in your development &#8211; don&#8217;t be afraid by the effort you need to spend to create them. Obviously you need to weigh up the benefits of the sophistication of the simulator with the effort to maintain them but there is often a nice balance to strike.</div>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/design/working-with-integration-points-simulators/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working With Integration Points: Anticorruption Layer</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/working-with-integration-points-anticorruption-layer/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/design/working-with-integration-points-anticorruption-layer/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 21:09:48 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=282</guid>
		<description><![CDATA[On my last few projects we had a requirement to integrate our application with another system. Adding to this complexity was the fact that these other systems where also still being developed. I learned a few tricks on the first of these types of projects which really helped the latter projects which I shall share [...]]]></description>
			<content:encoded><![CDATA[<div>On my last few projects we had a requirement to integrate our application with another system. Adding to this complexity was the fact that these other systems where also still being developed. I learned a few tricks on the first of these types of projects which really helped the latter projects which I shall share with a wider audience here.</div>
<div>The first of these tricks was to enforce a strict layering of my application and introduce an anti-corruption layer. This layer was responsible for dealing with the interface to the other system, and often hiding any crapiness of either the api or transport protocol from the rest of the application. It ensured that any business logic remained in the business services layer and any api/transport logic remained in the anti-corruption layer (which we called a wrapper).</div>
<div><a href="http://sarahtaraporewalla.com/thoughts/wp-content/uploads/2010/01/layered-diagram.jpg"><img class="size-medium wp-image-291 aligncenter" style="margin: 10px;" title="AntiCorruptionLayer" src="http://sarahtaraporewalla.com/thoughts/wp-content/uploads/2010/01/layered-diagram-300x201.jpg" alt="" width="300" height="201" /></a></div>
<div>The main reason for this was to limit the amount of damage that would occur should the api change (i.e. try to decrease the amount of coupling between the two systems). To support this, the wrapper would talk to the business services in domain language and pass around domain objects which it would transform into the required transport objects.</div>
<div>
<p>There are a few cases where the wrappers proved their worth:</p>
<ul>
<li>when the service did not populate all the necessary fields for the domain object</li>
<li>when the domain object did not logically contain a field necessary for the transport</li>
<li>when the business layers dealt in synchronous calls, and the api dealt with asynchronous calls</li>
<li>when the a wcf object type changed</li>
</ul>
</div>
<div>It was sometimes hard, especially when dealing with a crappy api that we could not alter, to know if a piece of logic should reside in the business service or in the wrapper. The general rule of thumb we followed was to ask ourselves &#8220;if we ever changed this integration point to a different system, would we still need this bit of logic?&#8221;. [The crappier the api the harder it was to answer].</div>
<div>However, despite what I considered to be the obvious benefits of introducing this layer, I faced a lot of resistance introducing it, especially when it looked like the business service was just a pass through to the wrapper i.e. when the method only had one line in it _wrapper.Foo() (actually it turned out that the only reason the service was pass through was because there were fat controllers &#8211; pushing the logic from the controller into the service made it look a lot healthier but that is a whole other discussion). What irked me the most is when people invoked YAGNI as a reason not to add a new object. Although that debate is a whole entire post in itself, all I am going to mention here is that YAGNI does not trump SOLID and that anti-corruption layers is nothing more than Single Responsibility Principle (i.e. Separation of Concerns) [and seriously - are you really telling me that adding another object is time consuming, in the world of resharper/intelli-j].</div>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/design/working-with-integration-points-anticorruption-layer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>I don&#8217;t believe in NFRs</title>
		<link>http://sarahtaraporewalla.com/thoughts/agile/i-dont-believe-in-nfrs/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/agile/i-dont-believe-in-nfrs/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 12:10:12 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=297</guid>
		<description><![CDATA[There is something about the phrase Non Functional Requirements that I don&#8217;t really like. It&#8217;s the Non bit which gets me &#8211; I think that word makes them feel unimportant and therefore there is no pressing need to explore how they will affect the system. I have seen on many projects teams procrastinating in defining [...]]]></description>
			<content:encoded><![CDATA[<p>There is something about the phrase <em><a title="Wikipedia: Non Functional Requirements" href="http://en.wikipedia.org/wiki/Non-functional_requirement" target="_blank">Non Functional Requirements</a></em> that I don&#8217;t really like. It&#8217;s the <em>Non</em> bit which gets me &#8211; I think that word makes them feel unimportant and therefore there is no pressing need to explore how they will affect the system. I have seen on many projects teams procrastinating in defining how the &#8220;NFRs&#8221; will affect what they are building &#8211; usually in the metrics around performance.</p>
<p>On my current project we have decided to appease my sensibilities and have called these <em><strong>Cross Functional Requirements</strong></em> to better express what they truly represent &#8211; requirements which cross all the functions we are building. So far the wording works &#8211; but we have only finished the 2nd week of inception.</p>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/agile/i-dont-believe-in-nfrs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Importance of Words</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/the-importance-of-words/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/design/the-importance-of-words/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 08:33:27 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=278</guid>
		<description><![CDATA[The english language is a very complex beast which can easily strike confusion in the most unsuspecting moment. Take, for example, the word &#8220;lollies&#8221;. Did your mind immediately jump to a bag of gummy bears, redskins, bananas or milk bottles that you get from the garage? Or instead did you start thinking of a frozen [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">The english language is a very complex beast which can easily strike confusion in the most unsuspecting moment. Take, for example, the word &#8220;lollies&#8221;. Did your mind immediately jump to a bag of gummy bears, redskins, bananas or milk bottles that you get from the garage? Or instead did you start thinking of a frozen dessert on a stick? If you thought the former, then, like me, you probably are Australian. Because the English term for it is sweets, and the American version is candy (although I doubt that they have such wonderful lollies as bananas and milk bottles). And the frozen-dessert-on-a-stick &#8211; thats an iceblock for me!</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Take another example &#8211; when Sisqo&#8217;s Thong Song came out I didn&#8217;t really understand why someone dedicate an entire song to $1 rubber plugs &#8211; until I watched the video clips and I realised that he wasn&#8217;t referring to &#8220;flip flops&#8221;.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">The lesson that I have learnt living in the UK is that I have to be very careful with the words that I use, lest I cause confusion by saying that someone was running around with their pants* off**.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">And this is also applies to the words and language that we use around our business, between developers and in our code. Too often, we describe concepts by words like &#8220;that thing&#8221; or &#8220;this stuff&#8221; which can obfuscate what it really is, and hence hinder our ability to model it. I often see complexity, misunderstandings and hacks creep into code bases when the original designer has referred to an information concept as &#8220;this thing&#8221; without taking the time to name it. I find that spending the energy, talking to the business to understand what you are really producing helps clarify understanding which in turn distills the model into a simpler, easily understood model.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">I had this demonstrated to me yesterday, when I came across a pair discussing how to &#8220;shove&#8221; this concept of &#8220;a thing that when clicked on opens up a popup with stuff in it&#8221; onto the model. As I listened to the conversation, I noticed just how muddled the model and the situation was becoming, so I decided to intervene with some of my words of wisdom about what they were trying to model. As soon as we worked out that the &#8220;a thing that when clicked on opens up a popup with stuff in it&#8221; translated into &#8220;a help message&#8221;, we were easily able to see exactly where in our model it should go.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">So, never underestimate the power of the words we use. When faced with a confusing concepts strive to distill it into easily understood, well defined names.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">* pants in Australia are trousers &#8211; pants in the English vernacular are what I call underpants.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">** yes I have once said that at work after I saw a pair of jeans on the table and was a little confused by what someone must be wearing!</div>
<p>The English language is a very complex beast which can easily strike confusion in the most unsuspecting moment. Take, for example, the word &#8220;lollies&#8221;. Did your mind immediately jump to a bag of <a href="http://en.wikipedia.org/wiki/Gummi_bear" target="_blank">gummy bears</a>, <a href="http://en.wikipedia.org/wiki/Redskins_(confectionery)" target="_blank">redskins</a>, <a href="http://www.goodygoodygumdrops.com.au/shop/images/pi_418.jpeg" target="_blank">bananas</a> or <a href="http://www.lollyworld.com.au/images/Allens-Milk-Bottles.jpg" target="_blank">milk bottles</a> that you get from the garage? Or instead did you start thinking of a <a href="http://en.wikipedia.org/wiki/Ice_pop" target="_blank">frozen dessert on a stick</a>? If you thought the former, then, like me, you probably are Australian. Because the English term for it is sweets, and the American version is candy (although I doubt that they have such wonderful lollies as bananas and milk bottles). And the frozen-dessert-on-a-stick &#8211; thats an iceblock for me!</p>
<p>Take another example &#8211; when <a href="http://en.wikipedia.org/wiki/Thong_Song" target="_blank">Sisqo&#8217;s Thong Song</a> came out I didn&#8217;t really understand why someone dedicate an entire song to<a href="http://upload.wikimedia.org/wikipedia/commons/thumb/6/65/Havi-flip1.JPG/180px-Havi-flip1.JPG" target="_blank"> $1 rubber plugs</a> &#8211; until I watched the video clips and I realised that he wasn&#8217;t referring to &#8220;<a href="http://en.wikipedia.org/wiki/Flip-flops" target="_blank">flip flops</a>&#8220;.</p>
<p>The lesson that I have learnt living in the UK is that I have to be very careful with the words that I use, lest I cause confusion by saying that someone was running around with their pants* off**.</p>
<p>And this is also applies to the words and language that we use around our business, between developers and in our code. Too often we describe concepts by words like &#8220;that thing&#8221; or &#8220;this stuff&#8221; which can obfuscate what it really is, and hence hinder our ability to model it. I often see complexity, misunderstandings and hacks creep into code bases when the original designer has referred to an information concept as &#8220;this thing&#8221; without taking the time to name it. I find that spending the energy talking to the business to understand what you are really producing helps clarify understanding which in turn distills the model into a simpler, easily understood model.</p>
<p>I had this demonstrated to me yesterday, when I came across a pair discussing how to &#8220;shove&#8221; this concept of &#8220;a thing that when clicked on opens up a popup with stuff in it&#8221; onto the model. As I listened to the conversation, I noticed just how muddled the model and the situation was becoming, so I decided to intervene with some of my words of wisdom about what they were trying to model. As soon as we worked out that the &#8220;thing that when clicked on opens up a popup with stuff in it&#8221; translated into &#8220;a help message&#8221;, we were easily able to see exactly where in our model it should go.</p>
<p>So, never underestimate the power of the words we use. When faced with a confusing concepts strive to distill it into easily understood, well defined names.</p>
<p>* pants in Australia are trousers &#8211; pants in the English vernacular are what I call underpants.<br />
** yes I have once said that at work after I saw a pair of jeans on the table and was a little confused by what someone must be wearing!</p>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/design/the-importance-of-words/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Refactor like a Something star</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/how-to-refactor-like-a-something-star/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/design/how-to-refactor-like-a-something-star/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 15:49:48 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=230</guid>
		<description><![CDATA[Refactoring a piece of code can be such a thrilling experience when it&#8217;s finished, but at the same time can also act as the blackhole of time. Recently, I have been observing how other people refactor, watching their looks of happiness when they finish it and also their despaired faces when they have realized they [...]]]></description>
			<content:encoded><![CDATA[<div>Refactoring a piece of code can be such a thrilling experience when it&#8217;s finished, but at the same time can also act as the blackhole of time. Recently, I have been observing how other people refactor, watching their looks of happiness when they finish it and also their despaired faces when they have realized they have spent a week trying to add one new argument to their method.</div>
<div>I love refactoring and I think I do a good job at it now, but there was a time in the not-so-distant past where I was one of those despaired faces. I got to where I am now thanks to pairing with refactoring gurus and practice. Here are some of the tricks that I have picked up:</p>
<ul>
<li><strong>Plan your refactoring</strong> Planning should never be considered overrated. Before I start a refactor, I like to assess everything that the existing code does, and map where I want that to sit. I also determine which angle is the best to start from after looking at all the possible combinations, so that I am always working with minimal changes. I like to use post-its to guide my work, so I usually start with a handful of post-its to show where I am going. If there are too many post-its, I also start questioning the scope of the refactor: what could I get done if I only had 2 days to do it in.</li>
<li><strong>Parallelize your work</strong> This really works well when, instead of shuffling bits around, you are actually doing a rewrite of the current functionality. For instance, the other day I rewrote the legacy login code to the application. Obviously I couldn&#8217;t be too ruthless as everyone needed to still login, and this code was not under test. So, I wrote the new login section alongside the existing code, and just swapping in my login code in the DI container on my local machine. When it was time to switch it over, we checked in the DI container change, and voila, everyone started using the new login code. This allowed us to check in frequently without breaking anyone regardless of it being incomplete. It also meant that we always had the original version to refer to as we proceeded</li>
<li><strong>Checkin often</strong> This is helped by either doing minimal changes at a time, or by parallelizing the work. Checkin frequently, checkin small. That way if you ever need to revert your changes, you know the brilliant work that you did before the &#8220;screwup&#8221; won&#8217;t be wasted. If you are working with a source control like mercurial or git, you are in an even better situation, as you still have source control without affecting the rest of your team with your breaking changes.</li>
<li><strong>Never be afraid to revert your changes</strong> This one is such a valuable lesson to learn and it feels so wrong when your doing faced with the possibility but when you have painted yourself into a corner, the best thing to do is to revert all changes. What it does mean, however, is that all the lessons that you learned from your first attempt will help guide your decisions the next time round.</li>
<li><strong>Prepare your system before you add new concepts</strong> I know that refactoring is all about improving your world without adding new functionality but sometimes people start adding new features before the world is setup for them. Ensuring that your world is good before you add new features will make your life simpler.</li>
<li><strong>Introduce new concepts top down</strong> Obvious? I thought so, but I have seen a refactoring go horribly wrong because it was started from the wrong place. When you change a class, you can isolate the changes within it, but every consumer of it will be affected. This bubbling effect can be catastrophic if you start from objects in the lowest level.</li>
<li><strong>Only have top level tests</strong> This one is slightly controversial, and I don&#8217;t know if I completely agree with it anyway, but if you only test your entry-point object, and never use fake objects during your testing (except to simulate external dependancies like databases or external services) then you will not have the annoyance of changing loads of unnecessary tests. You will also find that you can be 100% certain that your tests are still relevant without touching every single test file. </li>
<li><strong>Start with tests which pass</strong> Very important to ensure that you don&#8217;t break anything, so start with passing tests on the highest layer, whether that means browser based tests or controller tests. Make sure you have a test for all scenarios as that way you can easily test that your refactor has not changed the world.</li>
<li><strong>Making sure your world better than you found it (or at least no worse) reduces the number of big risky refactor adventures</strong></li>
</ul>
</div>
<div>
Do you have any other tricks that you use when you refactor?
</div>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/design/how-to-refactor-like-a-something-star/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Coding Tip #42: turning enums into classes</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/coding-tip-42-turning-enums-into-classes/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/design/coding-tip-42-turning-enums-into-classes/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 06:20:04 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=203</guid>
		<description><![CDATA[In Coding Tip #27 I explained how I rarely like to use booleans to represent states, and prefer to use an enum. Now that I have all nice little enums everywhere, another pattern that I see emerge is that I want more from my enum than just a value: perhaps other values associated with it, [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://sarahtaraporewalla.com/thoughts/design/coding-tip-27-turning-bools-into-enums/">Coding Tip #27</a> I explained how I rarely like to use booleans to represent states, and prefer to use an enum. Now that I have all nice little enums everywhere, another pattern that I see emerge is that I want more from my enum than just a value: perhaps other values associated with it, or actual behaviour. These enums then get converted into fully-fledged objects (ie classes) in the system with a very simple refactor. </p>
<p>So, the code started with:</p>
<pre class="brush: csharp;">
private bool hasVehicle;
</pre>
<p>then, by following <a href="http://sarahtaraporewalla.com/thoughts/design/coding-tip-27-turning-bools-into-enums/">Coding Tip #27</a>, went to:</p>
<pre class="brush: csharp;">
private Vehicle theVehicle;
public enum Vehicle
{
    Car,
    MotorBike,
    PeopleMover
}
</pre>
<p>and now can turn into:</p>
<pre class="brush: csharp;">
private Vehicle theVehicle;
public class Vehicle
{
    public static Vehicle Car = new Vehicle(&quot;Car&quot;);
    public static Vehicle MotorBike = new Vehicle(&quot;MotorBike&quot;);
    public static Vehicle PeopleMover = new Vehicle(&quot;PeopleMover&quot;);

    private Vehicle(string name)
    {
        this.name = name
    }
    private string name;
}
</pre>
<p>so my objects are all setup to add additional functionality:</p>
<pre class="brush: csharp;">
private Vehicle theVehicle;
...
theVehicle.WillSeatAPartyOf(4);
...
public class Vehicle
{
    public static Vehicle Car = new Vehicle(&quot;Car&quot;, 5);
    public static Vehicle MotorBike = new Vehicle(&quot;MotorBike&quot;, 2);
    public static Vehicle PeopleMover = new Vehicle(&quot;PeopleMover&quot;, 8);

    private Vehicle(string name, int passengerLimit)
    {
        this.name = name
        this.passengerLimit = passengerLimit;
    }
    private string name;
    private int passengerLimit;

    public bool WillSeatAPartyOf(int numberOfPassengers)
    {
        return numberOfPassengers =&lt; passengerLimit;
    }
}
</pre>
<p>I debate whether the class should contain the name or the index, usually I use the name; you can use both. Obviously if someone was now relying on the enum order, you would need to give it the index. Another advantage of this is because the constructor is private, you know that there are a definitive list of representations for it. </p>
<p>I don&#8217;t usually use class straight away. Indeed, I usually take bets to see how long it will stay an enum &#8211; sometimes the refactor is immediate, other times it remains an enum.</p>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/design/coding-tip-42-turning-enums-into-classes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>I don&#8217;t believe in ORM object as your domain model</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 22:45:31 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=204</guid>
		<description><![CDATA[I have been on a few projects now where we have used ORM libraries to help store our data (eg ActiveRecord for Rails, Hibernate (and it&#8217;s variants), Castle&#8217;s ActiveRecord for .Net). On these projects, we have used the domain models and the ORM models are the same.
The problem we faced with doing so is the [...]]]></description>
			<content:encoded><![CDATA[<p>I have been on a few projects now where we have used ORM libraries to help store our data (eg <a href="http://ar.rubyonrails.org/">ActiveRecord</a> for Rails, <a href="https://www.hibernate.org/">Hibernate</a> (and it&#8217;s variants), <a href="http://www.castleproject.org/activerecord/index.html">Castle&#8217;s ActiveRecord</a> for .Net). On these projects, we have used the domain models and the ORM models are the same.</p>
<p>The problem we faced with doing so is the same problems I think most people face : eventually, your domain wants to take your model in one direction, and your relational database wants to take it in another. Personally, I really like Domain Driven Design &#8211; I like my objects to be reflective of the domain &#8211; and I don&#8217;t really care about how the database stores them, or indexes or stuff like that (I seem to remember something about BNF back in uni), so I am more inclined to let my model move towards the domain; but I do understand that there are consequences in doing so when looking at how my data is accessed. </p>
<p>I have now come to the belief that there is value in having my domain models but equally having ORM models. More so, I have decided that (despite the perceived increase in classes) there is a true distinction between the two and should be implemented as two separate classes. You can see from my examples what I am talking about, but basically my domain model knows nothing about the ORM model and anyone (apart from the necessary repository) knows about it either. The ORM model is used by the repository of concern as a helpful tool for it to store to the database; it could equally be done using SQL. </p>
<pre class="brush: ruby;">
# The Domain model - yes there is more to it than that
class RegistrationForm

  def initialize(key)
    @key = key
    @name = &quot;&quot;
    @email = &quot;&quot;
  end
  ...
end
# The repository to find/save a registration
class RegistrationRepository

  def find(key)
    registration = find_registration(key)
    form = RegistrationForm.new
    return form unless registration
    update_form(form, registration)
  end

  def save(form)
    registration = find_registration(form[:key])
    registration = create_registration unless registration
    update_registration(registration, form)
    registration.save
  end

  private

    def find_registration(key)
      registration = Registration[:id =&gt; key]
     # This is the sequel equivalent of Registration.Find(key) in ActiveRecord
    end

    def create_registration
      registration = Registration.new
      registration
    end

    def update_form(form, registration)
      form.update(
        :key =&gt; registration.id,
        :name =&gt; registration.name,
        :email =&gt; registration.email)
      form
    end

    def update_registration(registration, form)
      registration.name = form[:name]
      registration.email = form[:email]
    end
end
# The ORM representation (using Sequel as my ORM library)
class Registration &lt; Sequel::Model
  set_schema do
    primary_key :id
    varchar :name
    varchar :email
  end
end
</pre>
<p>Maybe this is something that other folk have already thought of, and I am just catching up, but the proliferation of web MVC style frameworks which mandate persistence layers (eg Rails) makes be think that this may need to be revisited.</p>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Coding Tip #27: turning bools into enums</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/coding-tip-27-turning-bools-into-enums/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/design/coding-tip-27-turning-bools-into-enums/#comments</comments>
		<pubDate>Mon, 25 May 2009 15:48:51 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=162</guid>
		<description><![CDATA[On my recent project, I have noticed a resurgence in a pattern that I have seen many times previously: where a field which is represented as a boolean needs to evolve to represent more than just two values (true and false). The number of times that I have encounted this makes me believe that you should always start [...]]]></description>
			<content:encoded><![CDATA[<p>On my recent project, I have noticed a resurgence in a pattern that I have seen many times previously: where a field which is represented as a <em>boolean</em> needs to evolve to represent more than just two values (<em>true</em> and <em>false</em>). The number of times that I have encounted this makes me believe that you should always start with <em>enum</em>, regardless if the values are True and False, just to make your life easier down the line.</p>
<p>As much as refactoring tools like resharper help you out, when it comes to refactoring a bool into an enum, it&#8217;s a pain in the arm. One of these pain points being that quite often, you see:</p>
<p><code>if (fieldRepresentedByBool) {}</code></p>
<p>which makes it quite annoying to turn it into:</p>
<p><code>if (fieldNowRepresentedByEnum.Equals(Enum.True))</code></p>
<p>Another pain point is refactoring your database is not much fun, especially if you have to ensure that you also migrate data.</p>
<p>The other benefit that you get from enums when compared to booleans is that your method signatures are more expressive. Consider these two signatures (yes, I know completely contrived, but I couldn&#8217;t think of a better example), and tell me which one you prefer.</p>
<p><code>render(foo, true) // where true represents isVisible</code><br />
<code>render(foo, Display.Visible)</code></p>
<p>So, next time you start to type <em>bool</em> think about using an <em>enum</em> instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/design/coding-tip-27-turning-bools-into-enums/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>As a user I want to Log In</title>
		<link>http://sarahtaraporewalla.com/thoughts/agile/as-a-user-i-want-to-log-in/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/agile/as-a-user-i-want-to-log-in/#comments</comments>
		<pubDate>Wed, 20 May 2009 18:53:52 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=188</guid>
		<description><![CDATA[The classic log-in story is often the story that new-to-agile-ist assume you need to develop first. In fact, it is often the last story that should be developed.
The problem is that they see the order that stories should be developed in should mirror the process flow of the tasks that the customer needs to take; [...]]]></description>
			<content:encoded><![CDATA[<p>The classic log-in story is often the story that new-to-agile-ist assume you need to develop first. In fact, it is often the last story that should be developed.</p>
<p>The problem is that they see the order that stories should be developed in should mirror the process flow of the tasks that the customer needs to take; after all, you can&#8217;t buy an item without choosing what you want to buy and you can&#8217;t buy anything before you login. This might also be due to the stories revolving around the tasks the user needs to undertake instead of the goals they are trying to achieve.</p>
<p>Now,  if I was to build a classic shop-on-line website, the first story that I would start with would be to implement a page which accepts payment information and a Buy Now button in the middle of the page. What is the customer going to buy? The same product that every other customer will buy. Now, this does not seem to be that fantastic for the user &#8211; they don&#8217;t even have a choice in what they are buying, but this is actually the best place to start because it is not the <em>As a Customer I want to buy a book So that I can learn new stuff </em>story that we are implementing; it is the <em>As a Business Stakeholder I want customers to buy my products So that I can make a living </em>story. By defining our stories based on goals, and ordering the development based on what is more valuable, we can launch our site with only one story complete and still make money.</p>
<p>Now, lets go back to the beloved login story. One thing that I hate is a website which puts up a high barrier-to-entry before I can buy a product. At a real-life store, they don&#8217;t make me fill in a form to say who I am before I can buy my Big Mac meal; there is no real-world equivalent to the login functionality. What is the real reason that I as a customer needs to login? Where is the value? What is their goal? The next story in this area that you could play would be <em>As a Customer I want to view my purchse order in an email So that I can keep a record of the payment</em>. This story could just involve a text field where the user enters their email address if they wish to receive the email receipt (remember, back in the day, receipts from over-the-phone sales would be sent in the post). Again, we can go live with this and we are still not requiring the customer to login.</p>
<p>The final goal that summaries the customers experience is that<em> As a customer I would like the computer to do some work and remember their details So next time I make a purchase, I only need to place items in the basket and checkout</em>.  All this requires is the customers email address (a perfect URN by the way &#8211; why would you even think about having usernames???) and a password. Importantly, however, the gathering of this information does not need to occur before they purchase their items! It can happen at the end of the transaction, thereby allowing the customer to complete their goal (purchasing their items) without hinderence. </p>
<p>The customer&#8217;s goals are now met, and the business stakeholder&#8217;s goals were met in the very first story, it is only the marketers&#8217; goal of wanting to capture information about the customers on the site which has not been met. Usually marketting departments ask that the customers complete a 4 page registration form, in order for customers to register (<em>As a marketer I want to know information about our customers So that I can target our features to meet their needs</em>). But, what value or incentive is there for the customer to fill in this information? To appease both our market departments, and our customers, however, we could incentivise the customers by rewarding bonus points which go towards their next purchase for completing their registration form. But also importantly, this does not stop the customer from spending money on your site.</p>
<p>So, next time you go to add a login box on your site, think about what the customers true benefits are.</p>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/agile/as-a-user-i-want-to-log-in/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Making C# IList Useable</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/making-c-ilist-useable/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/design/making-c-ilist-useable/#comments</comments>
		<pubDate>Mon, 11 May 2009 13:17:25 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=169</guid>
		<description><![CDATA[Around my neck of the woods, I have been having a theoretical debate with my colleague Dan Bodart as to the best method signature when it comes to collections of data.
Dan&#8217;s point of view is that in order to be good citizens, our methods should form around interfaces and not rely on the concrete representation, [...]]]></description>
			<content:encoded><![CDATA[<p>Around my neck of the woods, I have been having a theoretical debate with my colleague <a title="Dan Bodart" href="http://dan.bodar.com/" target="_blank">Dan Bodart</a> as to the best method signature when it comes to collections of data.</p>
<p>Dan&#8217;s point of view is that in order to be good citizens, our methods should form around interfaces and not rely on the concrete representation, after all if you need the data as a list, you can always create a new one.</p>
<p>My argument is that the IList interface is so rubbish that you would always need to create a list in order to manipulate it, and then that just becomes noise.</p>
<p>Both sides of the argument have valid points, and valid critisisms. After a little searching, we have found the answer: use extension methods for IList to add the fantastic list methods to the interface. In fact, we have gone one step further, and added extention methods to IEnumerable, so that we can have the power for our dictionaries as well. We have taken the opportunity to add a lot more functional methods  such as Head, Tail, Exists,  Find and AsString.</p>
<p>Here is an exerpt from our class.</p>
<pre class="brush: csharp;">

    public static class EnumerableExtensionMethods

    {

        public static void ForEach&lt;T&gt;(this IEnumerable&lt;T&gt; source, Action&lt;T&gt; action)

        {

            foreach (T t in source)

            {

                action(t);

            }

        }

 

        public static List&lt;T&gt; ConvertAll&lt;S, T&gt;(this IEnumerable&lt;S&gt; source, Converter&lt;S, T&gt; converter)

        {

            return new List&lt;S&gt;(source).ConvertAll(converter);

        }

 

        public static List&lt;T&gt; FindAll&lt;T&gt;(this IEnumerable&lt;T&gt; source, Predicate&lt;T&gt; predicate)

        {

            return new List&lt;T&gt;(source).FindAll(predicate);

        }

    }
&lt;div&gt;</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/design/making-c-ilist-useable/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
