<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" 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:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>jon torresdal</title>
    <link>http://blog.torresdal.net/</link>
    <description />
    <language>en-us</language>
    <copyright>Jon Arild Tørresdal</copyright>
    <lastBuildDate>Sun, 23 Aug 2009 19:52:55 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8252.15582</generator>
    <managingEditor>blog@torresdal.net</managingEditor>
    <webMaster>blog@torresdal.net</webMaster>
    <image><link>http://blog.torresdal.net</link><url>http://blog.torresdal.net/images/NNUGImageOfMe.jpg</url><title>Image of Jon Arild Tørresdal</title></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/torresdal" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=c561b21e-7092-48b2-b74f-7e77385adb5b</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,c561b21e-7092-48b2-b74f-7e77385adb5b.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,c561b21e-7092-48b2-b74f-7e77385adb5b.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c561b21e-7092-48b2-b74f-7e77385adb5b</wfw:commentRss>
      <title>Live Meeting With Phil Haack On MVC 2 – August 26th</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,c561b21e-7092-48b2-b74f-7e77385adb5b.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/0VWv1ArFbUQ/LiveMeetingWithPhilHaackOnMVC2August26th.aspx</link>
      <pubDate>Sun, 23 Aug 2009 19:52:55 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;The &lt;a href="http://www.c4mvc.net/"&gt;Community For MVC.NET&lt;/a&gt; will be running a &lt;a href="http://www.c4mvc.net/MVCAugust09"&gt;Live Meeting with Phil Haack&lt;/a&gt; on August 26th @ 9am PST (4pm GMT / 6pm CET) on upcoming MVC 2 features.&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=c561b21e-7092-48b2-b74f-7e77385adb5b"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=0VWv1ArFbUQ:5ndYT2K2xfE:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=0VWv1ArFbUQ:5ndYT2K2xfE:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/0VWv1ArFbUQ" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,c561b21e-7092-48b2-b74f-7e77385adb5b.aspx</comments>
      <category>.Net</category>
      <category>ASP.NET</category>
      <category>Events</category>
      <category>MVC</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/08/23/LiveMeetingWithPhilHaackOnMVC2August26th.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=6eb830b7-e4a4-44fc-be7b-331665fd8fa4</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,6eb830b7-e4a4-44fc-be7b-331665fd8fa4.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,6eb830b7-e4a4-44fc-be7b-331665fd8fa4.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6eb830b7-e4a4-44fc-be7b-331665fd8fa4</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <title>Are SharePoint Developers Unable To Be Real Craftsmen?</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,6eb830b7-e4a4-44fc-be7b-331665fd8fa4.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/hrNi3u4koUU/AreSharePointDevelopersUnableToBeRealCraftsmen.aspx</link>
      <pubDate>Sat, 22 Aug 2009 22:46:38 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 5px 15px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://blog.torresdal.net/content/binary/WindowsLiveWriter/AreSharePointDevelopersUnableToAdhereToC_12927/image_3.png" width="204" height="139" /&gt;Even though I don’t develop software in SharePoint, &lt;a href="http://rapidapplicationdevelopment.blogspot.com/2009/08/sharepoint-wild-west-of-software.html"&gt;this blog&lt;/a&gt; post by Lee Richardson reflect my thoughts and worries about SharePoint development. &lt;/p&gt;  &lt;p&gt;The essence of his post is in this paragraph:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;But the power given to end users makes rigor and good design extremely hard for developers because the production machine you deployed to last month may look completely different now that you’re ready to redeploy. And Microsoft makes good design even harder with an inflexible API. Critical classes like SPSite (think SqlConnection) contain no public constructor, rendering them completely unmockable (unless you’re willing to spend $450 per developer for some &lt;/em&gt;&lt;a href="http://www.typemock.com/Buy.php"&gt;&lt;em&gt;TypeMock Isolator&lt;/em&gt;&lt;/a&gt;&lt;em&gt; magic). And vital classes like SPList (think DataSet) are marked final, crippling your ability to make nice strongly typed entities in your architectures.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Lee proposes some techniques to use that you should read in his post, but it’s half baked and not good enough in my opinion. The things he suggests (which is usually taken for granted on any other project) is made really hard to do by MS. Should MS rethink the way SharePoint is architected for the sake of developers to ease maintenance, improve code quality and basically allow developers working with ShapePoint to be craftsmen? Or is the dynamics of the product given to the end user so good that it’s worth all the extra efforts?&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=6eb830b7-e4a4-44fc-be7b-331665fd8fa4"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=hrNi3u4koUU:P1vgA1KbZrA:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=hrNi3u4koUU:P1vgA1KbZrA:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/hrNi3u4koUU" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,6eb830b7-e4a4-44fc-be7b-331665fd8fa4.aspx</comments>
      <category>.Net</category>
      <category>Architecture</category>
      <category>ASP.NET</category>
      <category>CleanCode</category>
      <category>Tools</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/08/22/AreSharePointDevelopersUnableToBeRealCraftsmen.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=fabad699-2a9a-4271-9f07-65eaaaaa54ab</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,fabad699-2a9a-4271-9f07-65eaaaaa54ab.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,fabad699-2a9a-4271-9f07-65eaaaaa54ab.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=fabad699-2a9a-4271-9f07-65eaaaaa54ab</wfw:commentRss>
      <title>The Current Direction Of Agile</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,fabad699-2a9a-4271-9f07-65eaaaaa54ab.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/URD76pEkGkg/TheCurrentDirectionOfAgile.aspx</link>
      <pubDate>Fri, 21 Aug 2009 04:03:39 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;&lt;a href="http://www.infoq.com/articles/current-direction-of-agile"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 15px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://blog.torresdal.net/content/binary/WindowsLiveWriter/TheCurrentDirectionOfAgile_555F/image_3.png" width="104" height="104" /&gt;&lt;/a&gt; A couple of days ago, my article about “&lt;a href="http://www.infoq.com/articles/current-direction-of-agile"&gt;The Current Direction Of Agile&lt;/a&gt;” was published on InfoQ. The article mainly represent my own learning curve within agile and lean inspired processes, hoping that my view would be interesting to others. I feel the recent Lean inspiration that agile has gotten the last couple of years, has pushed the agile community into a better place and been given tools to improve agile further.&lt;/p&gt;  &lt;p&gt;Thanks to &lt;a href="http://www.agilemanagement.net/Articles/Weblog/blog.html"&gt;David J. Anderson&lt;/a&gt; and &lt;a href="http://www.linkedin.com/pub/arlo-belshee/0/13b/ab"&gt;Arlo Belshee&lt;/a&gt; for reviewing the article, and not to forget &lt;a href="http://www.elssamadisy.com/about-amr.html"&gt;Amr Elssamadisy&lt;/a&gt; @ InfoQ for pointing me in the right direction.&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=fabad699-2a9a-4271-9f07-65eaaaaa54ab"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=URD76pEkGkg:OQKyzdk4M3o:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=URD76pEkGkg:OQKyzdk4M3o:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/URD76pEkGkg" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,fabad699-2a9a-4271-9f07-65eaaaaa54ab.aspx</comments>
      <category>Agile</category>
      <category>Articles</category>
      <category>InfoQ</category>
      <category>Lean</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/08/21/TheCurrentDirectionOfAgile.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=b2c34507-244a-424b-bc2a-d886201a4502</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,b2c34507-244a-424b-bc2a-d886201a4502.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,b2c34507-244a-424b-bc2a-d886201a4502.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=b2c34507-244a-424b-bc2a-d886201a4502</wfw:commentRss>
      <slash:comments>11</slash:comments>
      <title>Replace Comments With Code</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,b2c34507-244a-424b-bc2a-d886201a4502.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/wUO2R2iCT1E/ReplaceCommentsWithCode.aspx</link>
      <pubDate>Sun, 02 Aug 2009 22:36:48 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;It's tempting to just leave this blog post with that statement only :-) I will however explain this a bit further for those of you who either are forced to write comments (like by your boss or a policy at your company), or actually believe a lot of comments in code increase readability and ease maintenance.&lt;/p&gt;  &lt;p&gt;I'm not trying to be sarcastic, I just believe 100% in code and not in comments. In .NET and most other OO languages there are two types of comments. The first type is the one you write in your code to explain what your code does. Like this:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 525px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #008000"&gt;//Calculate interest&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;double&lt;/span&gt; amount 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    = balance * Math.Pow(1 + (annualPercentage / 100) / 365, days)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      - balance;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;How do you replace this comment with code? What about this:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 525px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;double&lt;/span&gt; amount = CalculateInterest(balance, annualPercentage, days);&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Whenever you come across comments like the above, I encourage you to refactor by replacing comments with code. Often you don't even have to extract a method like above, but just give better names to variables.&lt;/p&gt;

&lt;p&gt;The second type of comments is the ones you use to generate API documentation:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 525px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #808080"&gt;/// Calculate interest&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #808080"&gt;/// &amp;lt;param name=&amp;quot;balance&amp;quot;&amp;gt;Current balance of the account&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #808080"&gt;/// &amp;lt;param name=&amp;quot;annualPercentage&amp;quot;&amp;gt;Annual percentage&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #808080"&gt;/// &amp;lt;param name=&amp;quot;days&amp;quot;&amp;gt;Days to calculate interest for&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #808080"&gt;/// &amp;lt;returns&amp;gt;Interest amount&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; CalculateInterest(&lt;span style="color: #0000ff"&gt;double&lt;/span&gt; balance, 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; annualPercentage, 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; days)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Almost on every project I've been on we've had these comments/documentation. Also, on the same projects they've never been used for anything useful. I've actually forced devs to do this myself! If you're creating a product/framework to be used by other devs, writing this type of documentation makes sense. If you don't, it makes no sense! I used to do this just to satisfy my own satisfaction of generating a chm file and see that all my methods and classes was documented. That was about it. I never used it once! It's much easier to look in the code than to look at the API doc.&lt;/p&gt;

&lt;p&gt;The worst thing about this type of documentation is that it clutters your code and makes the code hard to read. A class with 50 lines of code becomes 100 lines with comments. As a practice, try to remove all comments and see if it's easier to understand and read the class. I strongly believe it is. If not, it's a code smell and you should refactor your code! Comments should not be used to explain bad code.&lt;/p&gt;

&lt;p&gt;When I talk to people about comments in code I often ask them two questions: &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Do you think it's hard to maintain code? &lt;/p&gt;

  &lt;p&gt;How hard to you think it is to maintain comments?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you change your code, do you also make sure to check if the comments are still correct after you've done the changes? Most people don't and you shouldn't really need to worry about it. Outdated comments can create confusion and bugs just because someone forgot to update them.&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=b2c34507-244a-424b-bc2a-d886201a4502"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=wUO2R2iCT1E:CJt3c1dKlZg:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=wUO2R2iCT1E:CJt3c1dKlZg:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/wUO2R2iCT1E" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,b2c34507-244a-424b-bc2a-d886201a4502.aspx</comments>
      <category>.Net</category>
      <category>Architecture</category>
      <category>CSharp</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/08/02/ReplaceCommentsWithCode.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=c79bd7a9-5c14-4d5e-a05d-da62f2dea07f</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,c79bd7a9-5c14-4d5e-a05d-da62f2dea07f.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,c79bd7a9-5c14-4d5e-a05d-da62f2dea07f.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c79bd7a9-5c14-4d5e-a05d-da62f2dea07f</wfw:commentRss>
      <title>Pricing For Azure</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,c79bd7a9-5c14-4d5e-a05d-da62f2dea07f.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/1iwy4zcJPUs/PricingForAzure.aspx</link>
      <pubDate>Sun, 19 Jul 2009 12:51:15 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;This escaped my radar. The pricing for Azure is now public. From &lt;a href="http://blogs.zdnet.com/microsoft/?p=3347"&gt;Mary-Jo Foley's blog&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Windows Azure:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Compute @&amp;#160; $0.12 / hour    &lt;br /&gt;Storage @ $0.15 / GB stored     &lt;br /&gt;Storage Transactions @ $0.01 / 10K&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;SQL Azure: &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Web Edition – Up to 1 GB relational database @ $9.99    &lt;br /&gt;Business Edition – Up to 10 GB relational database @ $99.99&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;.NET Services: &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Messages @ $0.15/100K message operations , including Service Bus messages and Access Control tokens&lt;/p&gt;  &lt;p&gt;Bandwidth across all three services will be charged at $0.10 in / $0.15 out / GB&lt;/p&gt;  &lt;p&gt;It's quite similar to Amazon's prices. Be interesting to see how long that lasts…&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=c79bd7a9-5c14-4d5e-a05d-da62f2dea07f"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=1iwy4zcJPUs:J323ANw8rBs:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=1iwy4zcJPUs:J323ANw8rBs:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/1iwy4zcJPUs" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,c79bd7a9-5c14-4d5e-a05d-da62f2dea07f.aspx</comments>
    <feedburner:origLink>http://blog.torresdal.net/2009/07/19/PricingForAzure.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=dae65808-c259-41d2-aeaa-14b78d60a94d</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,dae65808-c259-41d2-aeaa-14b78d60a94d.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,dae65808-c259-41d2-aeaa-14b78d60a94d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=dae65808-c259-41d2-aeaa-14b78d60a94d</wfw:commentRss>
      <slash:comments>7</slash:comments>
      <title>Start Using More Value Objects!</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,dae65808-c259-41d2-aeaa-14b78d60a94d.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/4-rqjv46YHI/StartUsingMoreValueObjects.aspx</link>
      <pubDate>Sun, 19 Jul 2009 11:29:12 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;At QCon London 2009, &lt;a href="http://qconlondon.com/london-2009/speaker/Dan+Bergh+Johnsson"&gt;Dan Bergh Johnsson&lt;/a&gt; had a talk on the DDD track about how to make use of Value Objects (VO's) (&lt;a href="http://qconlondon.com/london-2009/file?path=/qcon-london-2009/slides/DanBerghJohnsson_ThePowerOfValuePowerUseOfValueObjectsInDomainDrivenDesign.pdf"&gt;The Power of Value - Power Use of Value Objects in Domain Driven Design (PDF)&lt;/a&gt;). In his talk he took a piece of code and refactored it into a better piece of code by using VO's. By doing this Dan showed some really good concepts of using VO's. Even though I knew about the concept of VO's before his talk, he made me realize many new scenarios where they are applicable. And more importantly that it is not limited to DDD.&lt;/p&gt;  &lt;p&gt;So what is a VO anyway? Is it related to &lt;em&gt;value type&lt;/em&gt; in .NET? &lt;/p&gt;  &lt;p&gt;To answer the last question first: The real answer is no, but the way I see it there is a relation. A &lt;em&gt;value type &lt;/em&gt;in .NET is everything that is not an object. Typically simple types like int, char, double, but also enums and structs. The relation is that often you find yourself creating VO's where &lt;em&gt;value types &lt;/em&gt;was previously used. It is however not limited to &lt;em&gt;value types&lt;/em&gt;. &lt;/p&gt;  &lt;p&gt;Now to the first question. I first came across VO's after reading &lt;a href="http://www.amazon.co.uk/Domain-driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1247518163&amp;amp;sr=8-1"&gt;Evans DDD book&lt;/a&gt; (commonly known as the &lt;em&gt;blue book&lt;/em&gt;). In DDD a Value Object is an object without an Id and are usually immutable. In examples of VO's, Address is commonly used, which I don't find particularly useful. I think Address way too often has an Id and people have a hard time relating to that as a Value Object. I find the Amount example I gave in an &lt;a href="http://blog.torresdal.net/2009/06/22/RefactoringTryParseIntoAValueObject.aspx"&gt;earlier post&lt;/a&gt; to a better example or the one below illustrated as an interface (borrowed from Dan):&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 525px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IPhoneNumber {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; IsValid {&lt;span style="color: #0000ff"&gt;get&lt;/span&gt;;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Number {&lt;span style="color: #0000ff"&gt;get&lt;/span&gt;;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; AreaCode {&lt;span style="color: #0000ff"&gt;get&lt;/span&gt;;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;How many times have you used the concept of a phone number in your code? Like mobile, fax, fixed etc… How often have you kept it as a string? How much code do you have for doing different types of validation, getting area code etc? Do you have it all in one place or scattered around in different places? Other examples are Money, ZipCode etc… These are great candidates for Value Objects.&lt;/p&gt;

&lt;p&gt;Now that we know what Value Objects are, what is so powerful about them and why should I use them more? Great question :-) Below is my three reasons:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Code readability - I find that using Value Objects greatly improve the overall code readability and eliminates comments. Just like good names on methods and properties does. &lt;/li&gt;

  &lt;li&gt;DRY (Don't Repeat Yourself) - By having a Value Object for PhoneNumber, you avoid writing code to handle specific cases around phone numbers and you reuse them wherever the concept of a phone number is used. &lt;/li&gt;

  &lt;li&gt;Helps people getting back into OO thinking – We who have been living in the Microsoft .NET world for a long time have been thought to think of programming from a data/database perspective and not object oriented programming as we once learned it. In other words: think of behavior instead of data. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When I started to use VO's, I soon discovered I used them all over. They really add great value to my code. As an example, lets implement the IPhoneNumber above:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 525px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px" class="code"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; PhoneNumber : IPhoneNumber
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _phoneNumber;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; PhoneNumber(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; phoneNumber)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        _phoneNumber = phoneNumber;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; IsValid
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Regex.IsMatch(_phoneNumber, @&amp;quot;&lt;span style="color: #8b0000"&gt;^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$&lt;/span&gt;&amp;quot;); }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Number
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _phoneNumber; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; AreaCode
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Regex.Match(_phoneNumber, @&amp;quot;&lt;span style="color: #8b0000"&gt;^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})&lt;/span&gt;&amp;quot;).ToString();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The above code handles US phone numbers. To be used in a production system there should probably be even more validation in the regexp's, but I hope the example gives you and idea of what I'm thinking.&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=dae65808-c259-41d2-aeaa-14b78d60a94d"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=4-rqjv46YHI:CGRXw4Bjays:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=4-rqjv46YHI:CGRXw4Bjays:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/4-rqjv46YHI" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,dae65808-c259-41d2-aeaa-14b78d60a94d.aspx</comments>
      <category>.Net</category>
      <category>Architecture</category>
      <category>CSharp</category>
      <category>DDD</category>
      <category>Patterns</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/07/19/StartUsingMoreValueObjects.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=41c6c3cf-77ef-4954-90bd-8bc4f526138d</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,41c6c3cf-77ef-4954-90bd-8bc4f526138d.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,41c6c3cf-77ef-4954-90bd-8bc4f526138d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=41c6c3cf-77ef-4954-90bd-8bc4f526138d</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <title>Different Ways of Refactoring Switch/Case</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,41c6c3cf-77ef-4954-90bd-8bc4f526138d.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/dU-i9ipIP9M/DifferentWaysOfRefactoringSwitchCase.aspx</link>
      <pubDate>Sat, 18 Jul 2009 22:53:15 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;One of the code smells I see most often in C# and other OO languages is the misuse of switch/case statements. When I was a young Jedi (some might argue I still am :-)) I didn't see anything wrong with using the switch statement. Actually there still are a few cases where it's still applicable, but most usages I come across should have been solved differently. So why is this? What is so bad with the switch statement?&lt;/p&gt;  &lt;p&gt;As Dan North tweeted me when I asked for the perfect refactoring solution for switch statements :-) :&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;A switch is often a sign of behaviour that should live elsewhere - so where should the code in the cases live?&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Functions should only do one thing, the one thing which they state. Like CalculateInterest and ConvertDateToString should do exactly that; calculate interest and convert a date to string. Since switch always reside inside functions it almost always violates that principle.&lt;/p&gt;  &lt;p&gt;Let's look at what &lt;a href="http://blog.objectmentor.com/"&gt;Uncle Bob&lt;/a&gt; (Robert C. Martin) says in his &lt;a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882"&gt;Clean Code&lt;/a&gt; book about switch statements:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Even a switch statement with only two cases is larger than I'd like a single block or function to be. It's also hard to make a switch statement that does one thing. By their nature, switch statements always do N things.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;My answer to Dan's question above was using polymorphism. The cases should live in their own classes. By doing that you don't have to modify existing code when introducing new behavior, you just create a new state (read class). Btw Dan is really good at asking questions to questions where you end up answering your own question :-)&lt;/p&gt;  &lt;p&gt;Enough with the coding theory. Below is a method using a switch statement for getting messages from different systems. Typically these are systems that another system depends on (the system containing the below code). The messages might be if the system is available or not, or if there are any maintenance planned.&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 525px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetSystemMessage(System system)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (system)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; System.System1:
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetSystem1Message();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; System.System2:
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetSystem2Message();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; System.System3:
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetSystem3Message();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; System.System4:
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetSystem4Message();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;default&lt;/span&gt;:
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ApplicationException(&amp;quot;&lt;span style="color: #8b0000"&gt;System not found&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;This is actually quite a good switch. It uses return instead of break and it only has one line per case. If you can't avoid writing a switch, this is how you should do it.&lt;/p&gt;

&lt;p&gt;Now let's pull it apart and make it better and extendable. Time for refactoring. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Polymorphism by using Strategy Template Pattern 
    &lt;br /&gt;&lt;/strong&gt;Here's my code using the Strategy pattern:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 525px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; ISystemStrategy
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetMessage();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; System1Strategy : ISystemStrategy
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetMessage()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;System1&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; System2Strategy : ISystemStrategy
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetMessage()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;System2&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; System3Strategy : ISystemStrategy
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetMessage()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;System3&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; System4Strategy : ISystemStrategy
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetMessage()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;System4&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SystemMessenger
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; ISystemStrategy _system;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; SystemMessenger(ISystemStrategy system)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        _system = system;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetMessage()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _system.GetMessage();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;First I define an interface to be used by the different systems (ISystemStrategy) and next each system (1-4) implements that interface, resulting in a class for each case in the switch.In addition I have a class called SystemMessenger that is responsible for accessing the system and get a message. &lt;/p&gt;

&lt;p&gt;The switch can now be replaced by this code:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 525px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetSystemMessage(ISystemStrategy system)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SystemMessenger(system).GetMessage();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Note that the &amp;quot;client&amp;quot; only relates to the SystemMessenger class and not to the different implementations of ISystemStrategy. &lt;/p&gt;

&lt;p&gt;The benefit of this code might not be obvious. Actually it might give the impression that this was a lot of code for almost nothing. Well, don't be fooled. The strongest aspect of the above solution is that you don't have to change the GetSystemMessage later when/if a new system is added, you just implement a new class.&lt;/p&gt;

&lt;p&gt;To prove the above, here's what I need to do to introduce a new system:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 525px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; System5 : ISystemStrategy
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetMessage()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;System5&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;To use the new system, an instance of System5 will be sent into GetSystemMessage just as before, and SystemMessenger handles the rest as before. No code change!&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000"&gt;&lt;/font&gt;&lt;/p&gt;
&lt;strong&gt;Dictionary 
  &lt;br /&gt;&lt;/strong&gt;Another refactoring option is using some type of lookup table. In my example I'll use a dictionary together with the &lt;a href="http://msdn.microsoft.com/en-us/library/bb534960.aspx"&gt;Func&amp;lt;TResult&amp;gt;&lt;/a&gt; delegate. However, I don't recommend doing this unless you have a really good reason to do so. Stick with the Strategy pattern if you can. 

&lt;p&gt;&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 525px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SystemMessengerDictionary
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; Dictionary&amp;lt;System, Func&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;&amp;gt; _systems;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; SystemMessengerDictionary()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        _systems = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Dictionary&amp;lt;System, Func&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;&amp;gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                           {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                               {System.System1, GetSystem1Message},
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                               {System.System2, GetSystem2Message},
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                               {System.System3, GetSystem3Message},
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                               {System.System4, GetSystem4Message}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                           };
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetSystemMessage(System system)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _systems[system]();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    //GetSystemX Methods
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    ...
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;I decided to show this example even if I don't like it. The reason is that it is better than the switch. The worst about this in my eyes is that the enum is still there. I just hate enums! When reading the code they look like classes with interesting behavior, but then you discover they're just glorified int's :-|&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion 
    &lt;br /&gt;&lt;/strong&gt;Hopefully this example will help you understand why switch is something you should avoid and also give you an example of how it should be done. But before you consider doing any refactoring of existing code, consider a second question Dan asked (answered?) me:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;How would it evolve if you added a few more cases? And how likely are a few more cases?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is an important question, because you don't want to refactor just for the sake of refactoring. Keep this in mind before making use of any of the suggested solutions above.&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=41c6c3cf-77ef-4954-90bd-8bc4f526138d"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=dU-i9ipIP9M:ztfkAslm2FA:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=dU-i9ipIP9M:ztfkAslm2FA:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/dU-i9ipIP9M" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,41c6c3cf-77ef-4954-90bd-8bc4f526138d.aspx</comments>
      <category>.Net</category>
      <category>Architecture</category>
      <category>CSharp</category>
      <category>Patterns</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/07/18/DifferentWaysOfRefactoringSwitchCase.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=6e24585f-fdf8-4555-8776-1fa1b957694e</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,6e24585f-fdf8-4555-8776-1fa1b957694e.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,6e24585f-fdf8-4555-8776-1fa1b957694e.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6e24585f-fdf8-4555-8776-1fa1b957694e</wfw:commentRss>
      <title>WiX 3.0 Released</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,6e24585f-fdf8-4555-8776-1fa1b957694e.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/FHxjVGUccnA/WiX30Released.aspx</link>
      <pubDate>Sat, 18 Jul 2009 10:52:39 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;A bit late announcement from me, but 4th of July &lt;a href="https://sourceforge.net/projects/wix/files/"&gt;WiX version 3.0&lt;/a&gt; was &lt;a href="http://robmensching.com/blog/posts/2009/7/4/WiX-v3.0-released"&gt;declared stable&lt;/a&gt;. You can also find updated documentation for v.3.&lt;/p&gt;  &lt;p&gt;Regarding my focus on WiX lately I haven't done much in WiX for a while. I was planning to add some more posts to my &lt;a href="http://blog.torresdal.net/wix.aspx"&gt;WiX tutorials&lt;/a&gt;, but currently this has not been my priority after I changed job. I used to work for an ISV where deployment was very important. Where I currently work we're in full control of all servers we deploy to. I do however plan to do some stuff with WiX here as well, but that will have to be later.&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=6e24585f-fdf8-4555-8776-1fa1b957694e"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=FHxjVGUccnA:gEn3DHhPDD8:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=FHxjVGUccnA:gEn3DHhPDD8:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/FHxjVGUccnA" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,6e24585f-fdf8-4555-8776-1fa1b957694e.aspx</comments>
      <category>Deployment</category>
      <category>Events</category>
      <category>WiX</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/07/18/WiX30Released.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=c6b90404-b253-4663-98dc-89033e90d27d</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,c6b90404-b253-4663-98dc-89033e90d27d.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,c6b90404-b253-4663-98dc-89033e90d27d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c6b90404-b253-4663-98dc-89033e90d27d</wfw:commentRss>
      <slash:comments>9</slash:comments>
      <title>Refactoring TryParse Into a Value Object</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,c6b90404-b253-4663-98dc-89033e90d27d.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/3f7J1J8ul84/RefactoringTryParseIntoAValueObject.aspx</link>
      <pubDate>Mon, 22 Jun 2009 22:17:10 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;Recently I worked with a colleague on some code using decimal.TryParse() and tried to find a better way of using it. Specifically I had a string value representing a currency amount entered by a user in a web form. The amount needed more than just normal validation, so I needed to do some stuff with it.&lt;/p&gt;  &lt;p&gt;Here's the code I started with:&lt;/p&gt;  &lt;pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&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; SomeMethod(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; userEnteredAmount)
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;{
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;decimal&lt;/span&gt; amount;
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;decimal&lt;/span&gt;.TryParse(userEnteredAmount, &lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; amount) {
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;//Do some stuff with amount&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;//Show message to user about invalid amount&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;I've recently found many cases where I find the use of &lt;a href="http://dddstepbystep.com/wikis/ddd/value-object.aspx"&gt;Value Objects&lt;/a&gt; to be very applicable. I found this case to be a particularly interesting example. Anyway, I created a Value Object called Amount to abstract away the TryParse stuff. Below is the class I created.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&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; Amount
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;{
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;decimal&lt;/span&gt; _value;
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; _isValid;
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&lt;/span&gt;Amount(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; amount)
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    {
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        _isValid = &lt;span style="color: rgb(0, 0, 255);"&gt;decimal&lt;/span&gt;.TryParse(amount, &lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; _value);
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;decimal&lt;/span&gt; Value
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    {
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _value; }
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; IsValid
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    {
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _isValid; }
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;See how clean it got? At least I think so. The important part though is that it's usage is so much easier to understand and read:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;var amount = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Amount(userEnteredAmount);
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;(amount.IsValid) {
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;//Do some stuff with amount.Value&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;//Show message to user about invalid amount&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;It's more code, but cleaner. Or did I say that already? :-) And of course it's reusable other places where amount has a meaning.&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=c6b90404-b253-4663-98dc-89033e90d27d"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=3f7J1J8ul84:84GaP29sOOU:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=3f7J1J8ul84:84GaP29sOOU:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/3f7J1J8ul84" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,c6b90404-b253-4663-98dc-89033e90d27d.aspx</comments>
      <category>.Net</category>
      <category>CSharp</category>
      <category>DDD</category>
      <category>Patterns</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/06/22/RefactoringTryParseIntoAValueObject.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=182d3484-ad27-4afd-abe5-15315832f7ec</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,182d3484-ad27-4afd-abe5-15315832f7ec.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,182d3484-ad27-4afd-abe5-15315832f7ec.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=182d3484-ad27-4afd-abe5-15315832f7ec</wfw:commentRss>
      <title>Scott Hanselman and Jeremy D. Miller to NNUG Bergen!</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,182d3484-ad27-4afd-abe5-15315832f7ec.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/oEHCPJNMUxE/ScottHanselmanAndJeremyDMillerToNNUGBergen.aspx</link>
      <pubDate>Thu, 04 Jun 2009 11:08:05 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;As I’ve previously twitted through &lt;a href="http://twitter.com/nnugbergen"&gt;@nnugbergen&lt;/a&gt; and also through the invites I sent out yesterday, &lt;a href="http://www.hanselman.com/blog/"&gt;Scott Hanselman&lt;/a&gt; and &lt;a href="http://codebetter.com/blogs/jeremy.miller/"&gt;Jeremy D. Miller&lt;/a&gt; is coming to NNUG Bergen Monday the 15th of June (Jeremy) and Saturday 20th of June (Scott).&lt;/p&gt;  &lt;p&gt;Jeremy will do two talks. The first being Software Design and Testabillity and the second will be about StoryTeller, his take on integration testing. Scott will do his Deep Tour of .NET 4 talk. &lt;/p&gt;  &lt;p&gt;To sign up or see the full agenda, use the links below:&lt;/p&gt;  &lt;p&gt;Jeremy: &lt;a title="http://nnug.no/Avdelinger/Bergen/Moter/NNUG-Bergen---Juni-2009---Jeremy-D-Miller/" href="http://nnug.no/Avdelinger/Bergen/Moter/NNUG-Bergen---Juni-2009---Jeremy-D-Miller/"&gt;http://nnug.no/Avdelinger/Bergen/Moter/NNUG-Bergen---Juni-2009---Jeremy-D-Miller/&lt;/a&gt;    &lt;br /&gt;Scott: &lt;a title="http://nnug.no/Avdelinger/Bergen/Moter/NNUG-Bergen---Juni-2009---Scott-Hanselman/" href="http://nnug.no/Avdelinger/Bergen/Moter/NNUG-Bergen---Juni-2009---Scott-Hanselman/"&gt;http://nnug.no/Avdelinger/Bergen/Moter/NNUG-Bergen---Juni-2009---Scott-Hanselman/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In case you don’t know, all events going through NNUG is free, including these two! I’m already now worried how we’re going to top this next year. Maybe we should just close down NNUG Bergen after 2009 ;-)&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=182d3484-ad27-4afd-abe5-15315832f7ec"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=oEHCPJNMUxE:wiaZGm_deMs:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=oEHCPJNMUxE:wiaZGm_deMs:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/oEHCPJNMUxE" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,182d3484-ad27-4afd-abe5-15315832f7ec.aspx</comments>
      <category>Events</category>
      <category>NNUG</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/06/04/ScottHanselmanAndJeremyDMillerToNNUGBergen.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=4bb33d29-8fee-4710-a670-4b8078ce6fc5</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,4bb33d29-8fee-4710-a670-4b8078ce6fc5.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,4bb33d29-8fee-4710-a670-4b8078ce6fc5.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=4bb33d29-8fee-4710-a670-4b8078ce6fc5</wfw:commentRss>
      <title>Password Security Annoyances</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,4bb33d29-8fee-4710-a670-4b8078ce6fc5.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/rHJi1_0awXQ/PasswordSecurityAnnoyances.aspx</link>
      <pubDate>Sun, 17 May 2009 14:48:33 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;&lt;a href="http://blog.torresdal.net/content/binary/WindowsLiveWriter/PasswordSecurityAnnoyances_CB1F/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 15px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://blog.torresdal.net/content/binary/WindowsLiveWriter/PasswordSecurityAnnoyances_CB1F/image_thumb.png" width="150" height="150" /&gt;&lt;/a&gt; When so called secure institutions like banks, insurance companies and others ask you to create a password, you expect them to allow strange characters like ,.$#@{}[] to make the password stronger. To my surprise on several occasions I’ve experienced that they did not accept other than plain letters and numbers! What!? Didn’t the developer that implemented that logic raise a flag??&lt;/p&gt;  &lt;p&gt;One specific case is with BankId (a national authentication mechanism for all banks in Norway), where I know the underlying implementation support strong passwords. However, when prompted by my bank to create the password, you’re not permitted. Actually I had to type in a temporary weak password and then change the password in the login screen which support the expected behavior! &lt;/p&gt;  &lt;p&gt;At some point there had to be a discussion like this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Developer:&lt;em&gt; What type of password should we support?&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;Product Owner:&lt;em&gt; What do you mean?&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;Developer:&lt;em&gt; Should we allow people to make up their password from everything that they can find on their keyboard?&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;Product Owner:&lt;em&gt; No, the normal alphabet and numbers should be sufficient. Or else people just forget their passwords.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;My above experience with BankId was just an example from today, and in that case there were a workaround, which is not the common case. I always get puzzled when this happens. What puzzles me even more is that to prevent people from entering strong password, you actually have to code a business rule for exactly that! And what about those who only permit numbers!? What’s that all about?&lt;/p&gt;  &lt;p&gt;Sorry for this rant, but I think it is important that we as developers, architects and technically skilled people take responsibility to avoid stuff like this to happen. I just can’t see one single good reason for limiting the users choice when it comes to passwords.&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=4bb33d29-8fee-4710-a670-4b8078ce6fc5"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=rHJi1_0awXQ:i1eUUHb8NOg:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=rHJi1_0awXQ:i1eUUHb8NOg:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/rHJi1_0awXQ" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,4bb33d29-8fee-4710-a670-4b8078ce6fc5.aspx</comments>
      <category>Security</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/05/17/PasswordSecurityAnnoyances.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://blog.torresdal.net/Trackback.aspx?guid=6a09cfef-358b-4b89-8322-0678d112c588</trackback:ping>
      <pingback:server>http://blog.torresdal.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.torresdal.net/PermaLink,guid,6a09cfef-358b-4b89-8322-0678d112c588.aspx</pingback:target>
      <dc:creator>Jon Arild Tørresdal</dc:creator>
      <wfw:comment>http://blog.torresdal.net/CommentView,guid,6a09cfef-358b-4b89-8322-0678d112c588.aspx</wfw:comment>
      <wfw:commentRss>http://blog.torresdal.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6a09cfef-358b-4b89-8322-0678d112c588</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <title>Geek On Bike</title>
      <guid isPermaLink="false">http://blog.torresdal.net/PermaLink,guid,6a09cfef-358b-4b89-8322-0678d112c588.aspx</guid>
      <link>http://feedproxy.google.com/~r/torresdal/~3/Ryr_xbjajr4/GeekOnBike.aspx</link>
      <pubDate>Sat, 16 May 2009 16:27:10 GMT</pubDate>
      <description>&lt;div&gt;&lt;p&gt;&lt;a href="http://www.trekbikes.com/int/en/bikes/road/1_series/15/"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 15px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="Trek1_5" border="0" alt="Trek1_5" align="left" src="http://blog.torresdal.net/content/binary/WindowsLiveWriter/GeekOnBike_10112/Trek1_5_3.jpg" width="240" height="145" /&gt;&lt;/a&gt; This is a non technical post to add even more pressure on myself than the actual investment of my new bike and associated equipment. &lt;/p&gt;  &lt;p&gt;I found it was about time to add some physical fitness to my life other than moving from the computer to get coffee or to and from the car on my way to work :-)&lt;/p&gt;  &lt;p&gt;So this is a promise to myself (and now to the rest of the world I guess) that I will ride my new racing bike to and from work whenever the weather permits (read not snow or ice).&amp;#160; However, I might need a few weeks of training to actually physically be able to get to work on a bike :-)&lt;/p&gt;&lt;img width="0" height="0" src="http://blog.torresdal.net/aggbug.ashx?id=6a09cfef-358b-4b89-8322-0678d112c588"/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=Ryr_xbjajr4:TlREc6g7DYo:UQJ_KNDcA3w"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=UQJ_KNDcA3w" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/torresdal?a=Ryr_xbjajr4:TlREc6g7DYo:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/torresdal?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/torresdal/~4/Ryr_xbjajr4" height="1" width="1"/&gt;</description>
      <comments>http://blog.torresdal.net/CommentView,guid,6a09cfef-358b-4b89-8322-0678d112c588.aspx</comments>
      <category>Other</category>
      <category>Work</category>
    <feedburner:origLink>http://blog.torresdal.net/2009/05/16/GeekOnBike.aspx</feedburner:origLink></item>
  </channel>
</rss>
