<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Design and Architecture</title>
        <link>http://blogs.imeta.co.uk/HHariri/category/58.aspx</link>
        <description>Design and Architecture</description>
        <language>en-GB</language>
        <copyright>Hadi Hariri </copyright>
        <generator>Subtext Version 2.1.1.1</generator>
        <item>
            <title>It&amp;rsquo;s all about the delivery</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/10/29/itrsquos-all-about-the-delivery.aspx</link>
            <description>&lt;p&gt;   &lt;br /&gt;
The Dependency Inversion Principle states:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;dl&gt;&lt;dd&gt;&lt;dl&gt;&lt;dd&gt;&lt;em&gt;A. High-level modules should not depend on low-level modules. Both should depend on abstractions.&lt;/em&gt;&lt;/dd&gt;&lt;dd&gt;&lt;em&gt;B. Abstractions should not depend upon details. Details should depend upon abstractions.&lt;/em&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/dd&gt;&lt;/dl&gt;  &lt;br /&gt;
(Source WikiPedia).
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.codinghorror.com/blog/archives/001225.html"&gt;Throw that at a terrible programmer&lt;/a&gt;, and all you’ll get is a terrible programmer that is annoyed and hates you. So true!&lt;/p&gt;
&lt;p&gt;Take the following method:&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; PrintHelloMessage()&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            Console.WriteLine(&lt;span class="str"&gt;"Hello"&lt;/span&gt;);&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;p /&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;  
&lt;p&gt;Now ask a developer to add a new method to print the message ‘Goodbye’. Do you think he would do:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; PrintGoodbyeMessage()&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(&lt;span class="str"&gt;"Goodbye"&lt;/span&gt;);&lt;br /&gt;        }&lt;/pre&gt;
&lt;p&gt;   &lt;br /&gt;
or:&lt;/p&gt;
&lt;p /&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;  
&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; PrintMessage(&lt;span class="kwrd"&gt;string&lt;/span&gt; message)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(message);&lt;br /&gt;        }&lt;/pre&gt;
&lt;p /&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;  
&lt;p&gt;Most likely, he’d do the latter. Why? Because he realizes he’s gaining a benefit by passing a parameter to a method. He knows that if tomorrow you ask him for a “Good Afternoon” message, he won’t have to write a new method. &lt;/p&gt;
&lt;p&gt;What is Dependency Injection? It’s one way of complying with the Dependency Inversion Principle. However, when you think about it, what does it boil down to? Passing a parameter to a method, which happens to be a constructor. It seems simple enough doesn’t it? Yet, it’s hard for people to understand it. Why? because they don’t see the value in it. &lt;/p&gt;
&lt;p&gt;Explaining a principle to someone without them understanding the benefits and values they get out of it is useless, and that is why concepts such as Dependency Injection or Inversion of Control seem overly complex to the vast majority of developers (believe it or not, those of us that use these things are still a very big minority). It’s complex because they haven’t been explained the values of it. They’ve just been thrown some definition and they are expected to understand that it’s bad for one class to create an instance of another class it uses. &lt;/p&gt;
&lt;p&gt;Present a developer with the following code:&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AuthServices&lt;/pre&gt;
&lt;pre&gt;    {&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AuthUser(&lt;span class="kwrd"&gt;string&lt;/span&gt; username, &lt;span class="kwrd"&gt;string&lt;/span&gt; password)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            var authDAL = &lt;span class="kwrd"&gt;new&lt;/span&gt; AuthDAL();&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;            var user = authDAL.GetUserByUsername(username);&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (user != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre&gt;            {&lt;/pre&gt;
&lt;pre class="alt"&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; ...&lt;/pre&gt;
&lt;pre&gt;            }&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;pre class="alt"&gt;    }&lt;/pre&gt;
&lt;/div&gt;
&lt;p /&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;  
&lt;p&gt;and ask them how they’d go about testing this code without having access to a database. Ask them how they’d go about changing AuthDAL for some fake DAL that doesn’t really connect to a database. &lt;/p&gt;
&lt;p&gt;They’ll probably come up with the solution of passing the AuthDAL class in as a parameter, and eventually realizing that multiple methods will use the same class, they’ll pass it in via the constructor and set it as an instance field. As long as their AuthDAL has virtual methods, they can create any fake DAL that overrides those methods and returns some dummy value. They might argue that they don’t want virtual methods. And that’s fine. Tell them to define the parameter as an interface. In fact, they probably have already heard of a principle that says that you should program to an interface and not a class. They’ll eventually end up with this code:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AuthServices&lt;br /&gt;    {&lt;br /&gt;        IAuthDAL authDAL;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; AuthServices(IAuthDAL authDAL)&lt;br /&gt;        {&lt;br /&gt;            _authDAL = authDAL;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AuthUser(&lt;span class="kwrd"&gt;string&lt;/span&gt; username, &lt;span class="kwrd"&gt;string&lt;/span&gt; password)&lt;br /&gt;        {&lt;br /&gt;            var user = _authDAL.GetUserByUsername(username);&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (user != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; ...&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;And voila! You have Dependency Injection via Constructor. &lt;/p&gt;
&lt;p&gt;Once they *get* that, then explain to them other benefits, you know the real benefits they get from doing this: decoupled code, easy maintenance, promotion of SRP, etc.  and then throw the principle in their face:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;dl&gt;&lt;dd&gt;&lt;dl&gt;&lt;dd&gt;&lt;em&gt;A. High-level modules should not depend on low-level modules. Both should depend on abstractions.&lt;/em&gt; &lt;/dd&gt;&lt;dd&gt;&lt;em&gt;B. Abstractions should not depend upon details. Details should depend upon abstractions.&lt;/em&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/dd&gt;&lt;/dl&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;And they’ll see how it all makes sense. &lt;/p&gt;
&lt;p&gt;It’s not about throwing or not throwing books. It’s about showing people how something can help them, how they get value of it. &lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/800.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/10/29/itrsquos-all-about-the-delivery.aspx</guid>
            <pubDate>Thu, 29 Oct 2009 20:32:37 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/10/29/itrsquos-all-about-the-delivery.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/800.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/800.aspx</trackback:ping>
        </item>
        <item>
            <title>Upcoming talks</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/09/09/upcoming-talks-again.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;  &lt;p&gt;Start of the “conference season” again and I’ll be doing a tour of a few countries and places. Hope to meet up with some of you at some place and time. This time I’ll try and have all sessions ready so I can spend my time more productively at the bar/restaurant&lt;/p&gt;  &lt;p&gt;- 21st to 25th September at &lt;a href="http://www.basta.net"&gt;BASTA&lt;/a&gt;! in Germany. Talks on ASP.NET MVC, jQuery, TDD, Design Principles.&lt;/p&gt;  &lt;p&gt;- 27th to 30th September at &lt;a href="http://entwicklerkonferenz.de"&gt;Entwickler Konferenz&lt;/a&gt; in Germany. Talks on ASP.NET MVC, TDD.&lt;/p&gt;  &lt;p&gt;- 12th to 13th October at &lt;a href="http://www.devreach.com"&gt;DevReach&lt;/a&gt; in Bulgaria. Talks on ASP.NET MVC, Design Principles.&lt;/p&gt;  &lt;p&gt;- 16th to 17th October at TTT/&lt;a href="http://www.codecamp.es"&gt;CodeCamp&lt;/a&gt; in Tarragona. Talks on MEF and Design Principles.&lt;/p&gt;  &lt;p&gt;- 18th to 21st October at &lt;a href="http://www.sdc.nl"&gt;SDC&lt;/a&gt; in The Netherlands. Talks on ASP.NET MVC.&lt;/p&gt;  &lt;p&gt;- 29th October at Micrsoft in Madrid. Workshop on Design Principles (Link available soon)&lt;/p&gt;  &lt;p&gt;I’ve also pre-recorded 3 sessions for an online virtual conference on ASP.NET MVC, jQuery and Mocks, all in Delphi Prism and it’s happening right now on &lt;a href="http://conferences.embarcadero.com/coderage"&gt;CodeRage&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;-&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/752.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/09/09/upcoming-talks-again.aspx</guid>
            <pubDate>Wed, 09 Sep 2009 12:29:56 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/09/09/upcoming-talks-again.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/752.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/752.aspx</trackback:ping>
        </item>
        <item>
            <title>ASP.NET MVC &amp;quot;Models&amp;quot;: The lonesome folder!</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/05/07/asp.net-mvc-quotmodelsquot-the-lonesome-folder.aspx</link>
            <description>&lt;p&gt;ASP.NET MVC comes with a Models folder but no Model. Although some see this as a shortcoming, I'm actually delighted that the framework does not bind me to a specific data technology or pattern. If I want to use Active Record I can use Castle's ActiveRecord. If I want to use a Repository Pattern, I can use NHibernate. If I want to throw something together for a quick prototype, I can use Linq 2 Sql. The advantage of not being tied to a specific data access pattern for me is a win situation.&lt;/p&gt;  &lt;p&gt;In many a demo, it's been indicated that the  "Models" folder contains your model, whatever that happens to be. It could be your Domain Model, your L2S entities, etc.  Now there are obvious reasons that whatever model you have, you wouldn't include it into your ASP.NET MVC application directly. You would probably reference it as an external assembly, and not directly place it in the Models folder.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="367" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb.png" width="284" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;So this begs the question. Do we just remove the Models folder? Well before I answer that, let me dig into something else. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Binding in ASP.NET MVC&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We've seen many demos and tutorials where our model is directly passed in into our actions. We would have something along the lines of:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="291" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_2.png" width="484" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;ASP.NET MVC's binding is pretty powerful. It can reflect on the properties of your class (even if they contain complex types) and match these up to the properties that come through over the wire, via the request POST. As long as you name the properties the same, it works like a charm. One issue that this introduces, as outlined by &lt;a href="http://www.codethinked.com/post/2009/01/08/ASPNET-MVC-Think-Before-You-Bind.aspx"&gt;Justine in his post&lt;/a&gt;, as well as many others, is that the binding can come back to bite you. If you Customer entity has a field that you don't want the user to be able to update, you'll need to explicitly specify this by using attributes:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="82" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_3.png" width="495" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;However, as simple as it might seem, it's error prone and violates DRY. Alternatives to this approach include creating custom model binders or using interfaces to specify the properties that you want to be databound. But let's hold that thought for a moment. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;A typical update scenario for a typical entity&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The following screen has a sample form to fill in the details for a customer&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_10.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="302" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_4.png" width="474" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It's pretty standard. A bunch of fields and some dropdowns. But how is the dropdown values set? You could set them in the controller action just before displaying the view, using ViewData:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_12.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="94" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_5.png" width="636" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Now I don't know about you, but for me, using ViewData is a smell. If we don't use ViewData to pass information about our model, why should we be using it to pass information that our model indirectly consumes? And of course, being a dictionary that it is, it's prone to errors. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;One plus one makes habitants for Models folder&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We have two problems to solve:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Binding to only those properties that we need &lt;/li&gt;    &lt;li&gt;Passing additional information to our views in a strongly-typed manner &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Well this just cries out for a new class to encapsulate this information, i.e. a view model. Instead of binding directly to entities, you can bind to a new class that exposes only the information that is allowed to be updated. You can also use this class to provide other information required for a particular view. In the case of Customer, we could end up with something along the lines of:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_18.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="313" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_8.png" width="753" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;In this case, we are using CustomerData as a DTO to hold the customer data (Name, Email, etc.) and the CustomerCreateViewModel as the View Model to hold other pertinent information for that particular view, for instance a list of countries. The action would now pass in this model as opposed to Customer:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_20.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="143" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_9.png" width="744" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;We now have a strongly-typed model to represent all the information we need for a particular view, and since it pertains to the current MVC application and specific Views, what better place to hold this than the Models folder.  Obviously based on your needs, you could provide a flattened version of this ViewModel but it does provide a cleaner approach to separate the actual DTO of your entity from the surrounding &lt;em&gt;auxiliary&lt;/em&gt; requirements for a view.&lt;/p&gt;  &lt;p&gt;Note: you need to make sure that you always provide a default parameter-less constructor for your view models since the framework requires this on binding. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;By using strongly-typed views, you get the best of all worlds. You are able to make use of the binding provided by the MVC framework and it also provides a clean approach to providing specific data for views. And if that still doesn't cut it for you, think that you're making a home out of your Models folder!&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/692.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/05/07/asp.net-mvc-quotmodelsquot-the-lonesome-folder.aspx</guid>
            <pubDate>Thu, 07 May 2009 08:18:14 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/05/07/asp.net-mvc-quotmodelsquot-the-lonesome-folder.aspx#feedback</comments>
            <slash:comments>24</slash:comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/692.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/692.aspx</trackback:ping>
        </item>
        <item>
            <title>Balsamiq. Just wow!</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/03/13/balsamiq.-just-wow.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;  &lt;p&gt;Busy week for me this week. Between meetings, coding and real bad case of migraine, I've hardly had time to catch up with blogs or investigate new things. However, I did find a bit of time to look at two new tools, one of them being &lt;a href="http://www.balsamiq.com/"&gt;Balsamiq&lt;/a&gt; (the other tool, another blog post). I'd heard about &lt;a href="http://www.balsamiq.com/"&gt;Balsamiq&lt;/a&gt; some time ago but never really got round to playing with it until this week. And all I can see is that it's damn awesome. &lt;/p&gt;  &lt;p&gt;What is it? It's a tool to do mock-ups of UI's. What makes it awesome (apart from the really low price tag), is that it's extremely easy to use and powerful at the same time. Take a look at some screen mock-ups&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Balsamiq.Wow_ED09/image_8.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="367" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Balsamiq.Wow_ED09/image_thumb_3.png" width="630" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And here's the iPhone version of the "application"&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Balsamiq.Wow_ED09/image_4.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="396" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Balsamiq.Wow_ED09/image_thumb_1.png" width="235" border="0" /&gt;&lt;/a&gt;     &lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Balsamiq.Wow_ED09/image_6.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="292" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Balsamiq.Wow_ED09/image_thumb_2.png" width="495" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So in 5 minutes (literally), I threw up a few mock-ups of some UI that I can then show the customer. The cool thing is that it's so easy to use, you can actually have meetings with the customer using Balsamiq and come up with a design together. Here's an image of the the surface design with some random controls:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Balsamiq.Wow_ED09/image_10.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="401" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Balsamiq.Wow_ED09/image_thumb_4.png" width="590" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I remember when I was doing mock-ups years ago using RAD tools like Delphi / Visual Studio. Man does this save time.&lt;/p&gt;  &lt;p&gt;Love it! Definitely it's on my must-have-tools list. If you do any type of UI mock-ups, I highly recommend it. &lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/636.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/03/13/balsamiq.-just-wow.aspx</guid>
            <pubDate>Fri, 13 Mar 2009 16:21:52 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/03/13/balsamiq.-just-wow.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/636.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/636.aspx</trackback:ping>
        </item>
        <item>
            <title>Few days left for Early Bird for Architecture Days</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/03/11/few-days-left-for-early-bird-for-architecture-days.aspx</link>
            <description>&lt;p&gt;Just a few days left for the Early Bird fee for the iMeta Architecture Days. It's going to be a two day event in Madrid on Design Principles, Testing, and on the second day Domain Driven Design and SOA with &lt;a href="http://www.udidahan.com/"&gt;Udi Dahan&lt;/a&gt;! &lt;/p&gt;  &lt;p&gt;Since it's a training event, it's going to be a small group so there's more room for interaction.  And all this is for just a mere 375 Euros. Price includes lunch and munchies on both days.&lt;/p&gt;  &lt;p&gt;To sign up and more info, &lt;a href="http://apps.imeta.com/events/Home/EventDetails/1"&gt;click here&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/633.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/03/11/few-days-left-for-early-bird-for-architecture-days.aspx</guid>
            <pubDate>Wed, 11 Mar 2009 18:51:06 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/03/11/few-days-left-for-early-bird-for-architecture-days.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/633.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/633.aspx</trackback:ping>
        </item>
        <item>
            <title>Always room for improvement</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/03/08/you-dont-know-it-all.aspx</link>
            <description>&lt;p&gt;As if what Alt.NET is or isn't, whether it's &lt;a href="http://www.lostechies.com/blogs/chad_myers/archive/2009/03/01/alt-net-mean-how-do-we-fix-it.aspx"&gt;mean&lt;/a&gt; or not, wasn't enough, now we have a new guy on the &lt;a href="http://manifesto.softwarecraftsmanship.org/"&gt;scene&lt;/a&gt;, and already the &lt;a href="http://serialseb.blogspot.com/2009/03/why-im-not-signing-software.html"&gt;first reactions&lt;/a&gt; on the blogsphere (not to mention mailing lists and twitter world).&lt;/p&gt;
&lt;p&gt;Well before I give you my opinion, let me ask a couple of questions:&lt;/p&gt;
&lt;p&gt;Have you &lt;strong&gt;always&lt;/strong&gt; written applications that have been bug free? &lt;/p&gt;
&lt;p&gt;Have you &lt;strong&gt;always &lt;/strong&gt;written applications that were a breeze to change and changes would not introduce new bugs? &lt;/p&gt;
&lt;p&gt;Have you &lt;strong&gt;always &lt;/strong&gt;written applications were the code was easy to understand after not looking at it for 6 months or for a newcomer to the team?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I haven't. I've worked on applications were I used to not sleep a day before a new deployment, not knowing whether those last minute changes broke something. I've picked up applications that took me weeks to figure out. I've been on projects of 7+ people were the bus number has been as low as 1, both as a developer and as a stake holder. I've learnt from my errors and I am continuously trying to improve the way I develop software to avoid making the same mistakes I've made in the past. &lt;/p&gt;
&lt;p&gt;Unit testing, Test Driven Development, Dependency Inversion, Single Responsibility aren't required to make your software work. You don't need them to deliver applications. Your applications will still work without them. You can still link business logic to partial classes of datasets or hook them up directly to code-behind files in your ASPX pages. You can still use databinding with ObjectDataSources and your application will still work. You can still ship software that will work well for millions of hours with hundreds of thousands of users connected to it. &lt;/p&gt;
&lt;p&gt;However, I'm quite certain that you'll suffer the consequences. I'm pretty sure, having been on both sides of the fence, that it will be easier to make a change to an application where you have a clear separation of concerns as opposed to the drag-and-drop version. It will be more re-assuring to make a change and have 90% of your unit tests pass, fix the remaining 10% and then deploy, as opposed to just ship and hope for the best. &lt;/p&gt;
&lt;p&gt;That's why I write unit tests, to try and catch as many bugs that I introduce when making changes to existing software. That's why I apply principles such as SOLID, to make my code easier to change and more understandable&lt;/p&gt;
&lt;p&gt;Alt.Net or the recent manifesto of &lt;a href="http://manifesto.softwarecraftsmanship.org/"&gt;Software Craftsmanship&lt;/a&gt; for me represent ways to improve my job and myself. Ways to develop software that will make it easier for me. At the end of the day, what I care about is what I'm responsible for, and that is myself, my team and the software I write. It's not about making a statement or trying to change the world. Another matter is if I choose to share my experiences with others, which I'm free to do. But it's not about forcing one way over the other. &lt;/p&gt;
&lt;p&gt;Maybe the ways that I've learnt to improve up to now are not entirely correct. Maybe tomorrow we'll find better ways to write software, to make our life easier. However, I know that what I'm doing today is better than what I did yesterday. But that can only be accomplished if I'm willing to accept that I &lt;span style="font-weight: bold;"&gt;&lt;strong&gt;don't &lt;/strong&gt;know it all and I'm open to improvement. &lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/627.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/03/08/you-dont-know-it-all.aspx</guid>
            <pubDate>Sun, 08 Mar 2009 19:16:52 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/03/08/you-dont-know-it-all.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/627.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/627.aspx</trackback:ping>
        </item>
        <item>
            <title>DDD Series</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/02/20/ddd-series.aspx</link>
            <description>&lt;p&gt;If you're interested in Domain Driven Design, make sure you follow &lt;a href="http://devlicio.us/blogs/casey/archive/tags/DDD/default.aspx"&gt;Casey's series&lt;/a&gt; on the subject. He does a very good job of explaining things clearly and answers many obvious questions that one initially asks when starting with DDD. Make sure you check out the comments also.&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/615.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/02/20/ddd-series.aspx</guid>
            <pubDate>Fri, 20 Feb 2009 20:16:24 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/02/20/ddd-series.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/615.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/615.aspx</trackback:ping>
        </item>
        <item>
            <title>I'm not a Coding Horror, are you?</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/02/14/im-not-a-coding-horror-are-you.aspx</link>
            <description>&lt;p&gt;According to you &lt;a href="http://www.codinghorror.com"&gt;Jeff&lt;/a&gt;, 80% of developers are people that don't care much about improving the quality of their craft. In other words, it's mostly those who just care about the paycheck...programming is a job that pays the bills.&lt;/p&gt;  &lt;p&gt;The remaining 20% fall in the category of those that read your blog (note the part in &lt;em&gt;Italics&lt;/em&gt;):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;But here's the paradox: the types of programmers who would most benefit from these guidelines, rules, principles, and checklists are the least likely to read and follow them. &lt;b&gt;Throwing a book of rules at a terrible programmer just creates a terrible programmer with a bruise on their head where the book bounced off.&lt;/b&gt; This is something I discussed previously in &lt;a href="http://www.codinghorror.com/blog/archives/001004.html"&gt;Mort, Elvis, Einstein, and You&lt;/a&gt;: &lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;blockquote&gt;&lt;em&gt;Thus, if you read the article, you are most assuredly in the twenty percent category. The other eighty percent are not actively thinking about the craft of software development. They would never find that piece, much less read it. They simply don't read programming blogs-- other than as the result of web searches to find quick-fix answers to a specific problem they're having. Nor have they read any of the books in my &lt;/em&gt;&lt;a href="http://www.codinghorror.com/blog/archives/000020.html"&gt;&lt;em&gt;recommended reading list&lt;/em&gt;&lt;/a&gt;&lt;em&gt;. The defining characteristic of the vast majority of these so-called "vocational" programmers is that they are unreachable. It doesn't matter what you, I or anyone else writes here -- they'll never see it. &lt;/em&gt;&lt;/blockquote&gt;    &lt;p&gt;In the absence of mentoring and &lt;a href="http://www.codinghorror.com/blog/archives/000446.html"&gt;apprenticeship&lt;/a&gt;, the dissemination of better programming practices is often conveniently packaged into &lt;a href="http://en.wikipedia.org/wiki/Software_engineering_methodology#Specific_software_development_methodologies"&gt;processes and methodologies&lt;/a&gt;. How many of these do you know? How many have you practiced? &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Yet at the same time, as author of this blog and thus falling in the 20%, you state:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;All those incredibly detailed rules, guidelines, methodologies, and principles? YAGNI. If it can't be explained on a single double-spaced sheet of paper, it's a waste of your time. Go read and write some code!&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;So which is it Jeff? Do we or don't we try and improve ourselves? &lt;/p&gt;  &lt;p&gt;I don't fall into either of the groups, I'm not a Coding Horror. I'm one of those guys that tries to improve my knowledge, I try and learn continuously, either by myself or with the help of those that surround me. I don't just throw it all out of the window and claim that if there isn't a mentor around to help me, screw it. I don't give up if I can't understand it in a few hours. If others do differently, I try and understand why they do it differently.  &lt;/p&gt;  &lt;p&gt;To claim that I'm not going to need to, or not change my ways is very arrogant on my behalf. And the best thing is that I'm not alone. There are thousands of others like me. &lt;/p&gt;  &lt;p&gt;So please Jeff, don't corrupt the profession just to justify your own ways.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;[And to my reader (Hi Mom!), I will do my utmost best to refrain from writing any more posts about Coding Horror]&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/610.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/02/14/im-not-a-coding-horror-are-you.aspx</guid>
            <pubDate>Sat, 14 Feb 2009 15:37:09 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/02/14/im-not-a-coding-horror-are-you.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/610.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/610.aspx</trackback:ping>
        </item>
        <item>
            <title>Demoware Cowboys</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/02/12/demoware-cowboys.aspx</link>
            <description>&lt;p&gt;My mother wants to become a computer programmer (not to be taken literally). And guess what, she can. With all the RAD environments nowadays you really don't need to know much about the basics of programming to &lt;strong&gt;make applications&lt;/strong&gt;. You can use anything you want. First step, pick an environment. You have lots to choose from (Visual Studio, Delphi, Ruby on Rails). In under 1 hour you'll have your first application working. Next step, sell it. &lt;/p&gt;
&lt;p&gt;Now do this for about 10 years, making a profit and you can claim that you're successful in software development. You can claim you've worked for 10 years and have never had to worry about things such as polymorphism, delegation, etc. &lt;/p&gt;
&lt;p&gt;So when someone comes along with a &lt;a href="http://www.codinghorror.com/blog/archives/001225.html"&gt;post&lt;/a&gt; talking about weird things such as SOLID or how rules are meant to be broken, you reaffirm your position as a successful developer that has never needed or understood these concepts. And since the &lt;a href="http://www.codinghorror.com"&gt;person&lt;/a&gt; writing this has 1.5M visitors a month and 125K subscribers, it's OK! &lt;/p&gt;
&lt;p&gt;(You think I'm crazy. Read some of the comments on this &lt;a href="http://www.codinghorror.com/blog/archives/001225.html"&gt;post&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong /&gt;&lt;/p&gt;
&lt;strong&gt;&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt; &lt;/strong&gt; &lt;/strong&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;strong&gt;&lt;strong&gt;But It's NOT OK&lt;/strong&gt;&lt;/strong&gt;&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;strong&gt;&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt; &lt;/strong&gt; &lt;/strong&gt;
&lt;p&gt;I don't lose sleep over what I term demoware cowboys. Everyone has a right to make a living, however way they want. I'm the first person in the room that stands up to defend not needing to graduate in CS to have a successful career in software development. However, I also defend studying, understanding and practicing software engineering, and to continuously improve yourself. Just because you sell software and put food on the table doesn't mean you've accomplished all there is to in your field. &lt;/p&gt;
&lt;p&gt;What does bother me however is people &lt;a href="http://www.joelonsoftware.com/items/2009/01/31.html"&gt;talking&lt;/a&gt; about things without truly understanding them. It's important to act with responsibility, specially when having so many &lt;em&gt;followers&lt;/em&gt;. &lt;/p&gt;
&lt;p&gt;Some of us write software for a living, &lt;a href="http://www.codinghorror.com/blog/archives/001074.html"&gt;as opposed to just writing about it&lt;/a&gt;, and it's not only about getting the job done.&lt;br /&gt;
&lt;strong&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;br /&gt;
&lt;/strong&gt;&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/604.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/02/12/demoware-cowboys.aspx</guid>
            <pubDate>Thu, 12 Feb 2009 08:12:34 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/02/12/demoware-cowboys.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/604.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/604.aspx</trackback:ping>
        </item>
        <item>
            <title>Additional code just for testing</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/02/08/additional-code-just-for-testing.aspx</link>
            <description>&lt;p&gt;Take a look at this code:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; ClassToTest {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;  &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; MethodToTest()&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;         &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;         IDAL dal = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; DAL();&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;  &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; discount = dal.GetDiscount();&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;  &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (discount &amp;gt; 10)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;         {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Do something&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;         }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;  &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The tight coupling to DAL just stands out like a sore thumb. One consequence of this tight coupling is that it's hard to test if we don't have an underlying database setup with correct values. Forget about testing this while taking a shower, unless you have a habit of taking your SQL Server box to the bath tub with you. &lt;/p&gt;
&lt;p&gt;Take a look at the following approach to making this code testable without having a database:&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; ClassToTest {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;  &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; MethodToTest()&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;         &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;         DAL dal = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; DAL();&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;         &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;         &lt;span style="color: rgb(204, 102, 51);"&gt;#if&lt;/span&gt; testing_in_shower&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; discount = 3;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         &lt;span style="color: rgb(204, 102, 51);"&gt;#else&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; discount = dal.GetDiscount();&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;         &lt;span style="color: rgb(204, 102, 51);"&gt;#endif&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (discount &amp;gt; 10)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;         {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Do something&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;         }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;  &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Are you still here? Didn't you just fall off of your chair, not knowing whether to laugh or cry in anguish? It's just plain wrong isn't it? &lt;em&gt;Code Smell&lt;/em&gt; just takes on a whole new dimension (and consistency?). Something like this shouldn't be done for many reasons. It makes our code testable but it's wrong. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Introducing code for testing purposes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The reason I bring this up now is because in the past 2 weeks I've seen a few references and examples of introducing code just for the sake of testability. Two weeks ago I was skimming over an article that was explaining unit tests. The class the author was trying to test had a dependency that was causing issues during his tests. The solution offered was to introduce a new constructor and inject the dependency in. In our case, the ClassToTest would like: &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; ClassToTest {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;  &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; ClassToTest()&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;         &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Initialize some stuff&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;  &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;  &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; ClassToTest(IDAL dal)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Initialize some stuff&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;         _dal = dal;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;  &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; ....&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now that's great. The problem is that the author left both constructors in there, emphasizing that one is for testing purposes and the other for production code. Why that's wrong I'll get to in a moment. &lt;/p&gt;
&lt;p&gt;The other day, Scott Hansleman made a &lt;a href="http://www.hanselman.com/blog/IPrincipalUserModelBinderInASPNETMVCForEasierTesting.aspx"&gt;blog post&lt;/a&gt; on testing some code that had a dependency on the current principal. His solution was to inject IPrincipal into various methods of the Controller, where Controller is in the context of an ASP.NET MVC Controller. Personally I don't agree with the solution but that's another subject (and another post on a different approach I have in the backlog for the same scenario). However, injecting the dependency seemed valid enough. Later on he updated the post with the following:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;UPDATE: &lt;/strong&gt;Phil had an interesting idea. He said, why not make method overloads, one for testing and one for without. I can see how this might be controversial, but it's very pragmatic.&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;[Authorize]  &lt;/li&gt;
    &lt;li&gt;public ActionResult Edit(int id)  &lt;/li&gt;
    &lt;li&gt;{  &lt;/li&gt;
    &lt;li&gt;return Edit(id, User); //This one uses HttpContext &lt;/li&gt;
    &lt;li&gt;}  &lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;[Authorize]&lt;br /&gt;public ActionResult Edit(int id)&lt;br /&gt;{&lt;br /&gt;    return Edit(id, User); //This one uses HttpContext&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;You'd use this one as before at runtime, and call the overload that takes the IPrincipal explicitly for testing. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The same thing has happened as in the case of an overloaded constructor. Code has been introduced into the base just for the sake of testability. In the previous case it was a new constructor, and in this case, a new method.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why is this wrong?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Introducing code just so that you can test it is wrong for several reasons, including an increase in noise, decrease in readability and more importantly, permitting the possibility of production code that will not be tested. It might seem improbable at first, seeing that the overloaded versions always call the base ones, but as your code base grows, by allowing this habit, you can promote it to other structures such as conditionals, switch statements, etc, and not limit it only to methods or constructors. Then you'll start initializing values that only make sense in tests and gradually your code starts to smell more and more. To top it off, you can throw in some compiler conditional that rips those parts of the code out from the production version.&lt;/p&gt;
&lt;p&gt;Code should also serve as documentation. The cleaner you make your code, the less noise and redundancy you add, the easier it is for others to understand and maintain. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Being pragmatic is good, but don't do it at any cost. Try and not introduce code into your code base that is there exclusively for the purpose of testability (and no, dependency injection is not only for testability). Anything that has to do with testing, keep it where it should be, in the test assemblies. Having overloaded methods or constructors, mocks or stubs in your code base is just as bad as having compiler conditionals in your code for testability. If you run into issue where your code is hard to test, step back and re-think your design. Maybe the problem you're facing now that's impeding your tests is actually a can of worms waiting to be opened. And the sooner you open it, the better. That's one of the great advantages of Test Driven Development.&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/599.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/02/08/additional-code-just-for-testing.aspx</guid>
            <pubDate>Sun, 08 Feb 2009 12:06:36 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/02/08/additional-code-just-for-testing.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/599.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/599.aspx</trackback:ping>
        </item>
    </channel>
</rss>