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

<channel>
	<title>Randy Patterson &#187; Patterns</title>
	<atom:link href="http://RandyPatterson.com/index.php/category/patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://RandyPatterson.com</link>
	<description>Code To Live, Live To Code</description>
	<lastBuildDate>Sat, 24 Apr 2010 01:18:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Lazy Instantiation with Unity Application Block</title>
		<link>http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/</link>
		<comments>http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/#comments</comments>
		<pubDate>Sun, 30 Mar 2008 05:48:37 +0000</pubDate>
		<dc:creator>randypatterson</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Unit Tests]]></category>
		<category><![CDATA[Unity Application Block]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://localhost/2008/03/30/LazyInstantiationWithUnityApplicationBlock.aspx</guid>
		<description><![CDATA[Configuring the Unity Application Block for just-in-time Instantiation.&#160; 
Out of the box, Unity does not provide a way to configure your dependencies so that they are resolved only if needed.&#160; Lazy Instantiation would be desirable if your dependency is and required only under certain circumstances or you would like to delay object creation of a [...]]]></description>
			<content:encoded><![CDATA[<p>Configuring the <a href="http://codeplex.com/unity" target="_blank">Unity Application Block</a> for just-in-time Instantiation.&nbsp; </p>
<p>Out of the box, Unity does not provide a way to configure your dependencies so that they are resolved only if needed.&nbsp; Lazy Instantiation would be desirable if your dependency is and required only under certain circumstances or you would like to delay object creation of a resource intensive dependency until needed.</p>
<p>For <a href="http://en.wikipedia.org/wiki/Lazy_initialization_pattern" target="_blank">Lazy Instantiation</a>, the first obstacle to overcome when using <a href="http://martinfowler.com/articles/injection.html" target="_blank">IoC Containers</a> like <a href="http://codeplex.com/unity" target="_blank">Unity</a>, is to have your components get a reference to the container so the dependency creation can be delegated to it when the need arises.&nbsp; My first inclination was to wrap Unity in a <a href="http://en.wikipedia.org/wiki/Singleton_pattern" target="_blank">Singleton</a> and have the component reference this in order to resolve the dependency.&nbsp; </p>
<p><font size="3">Container.Instance.Resolve&lt;<font color="#07c7fe">IProductService</font>&gt;();</font></p>
<p>Singleton&#8217;s are, however, notoriously difficult to test and very rigid in design.&nbsp; Used in this manner,&nbsp; a Singleton is nothing more than a global variable wrapped in a buzzword.&nbsp; so I wanted a different approach.&nbsp; Since we are using a <a href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank">Dependency Injection</a> Framework, why not have the container inject a reference to itself into our components.</p>
<p>1.&nbsp; First, configure the Unity container so that it can return a reference to itself.</p>
<p><a href="http://www.randypatterson.com/images/Gettingareferencetothecurrentunitycontai_B90C/image1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="65" alt="image" src="http://www.randypatterson.com/images/Gettingareferencetothecurrentunitycontai_B90C/image1_thumb.png" width="526" border="0"></a> </p>
<p>2.&nbsp; Next, create a property on your class to get a reference to the Unity container that created it.</p>
<p><a href="http://www.randypatterson.com/images/Gettingareferencetothecurrentunitycontai_B90C/image10.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="119" alt="image" src="http://www.randypatterson.com/images/Gettingareferencetothecurrentunitycontai_B90C/image10_thumb.png" width="341" border="0"></a> </p>
<p>3.&nbsp; Finally, have the container resolve the dependency the first time it&#8217;s referenced.&nbsp; </p>
<p><a href="http://www.randypatterson.com/images/Gettingareferencetothecurrentunitycontai_B90C/image16.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="181" alt="image" src="http://www.randypatterson.com/images/Gettingareferencetothecurrentunitycontai_B90C/image16_thumb.png" width="548" border="0"></a> </p>
<p><font size="3"></font><font size="3">Unit Testing</font></p>
<p>Testing is straight forward as well.&nbsp;&nbsp; You could have your unit test use reflection to reach in and set the private field (_productService) to your mock object.&nbsp; However,&nbsp; giving your Unit Tests access to private members violates the &#8220;<a href="http://xunitpatterns.com/Principles%20of%20Test%20Automation.html#Use%20the%20Front%20Door%20First" target="_blank">Use the Front Door First</a>&#8221; Test Automation Principle and should be avoided if possible.&nbsp; Alternatively, you could create a mock object for IUnityContainer and have it return a mock object for IProductService when the Resolve method is called.</p>
<p>Using <a href="http://www.ayende.com/projects/rhino-mocks/downloads.aspx" target="_blank">RhinoMocks</a>, the Unit Test would look something like this:</p>
<p>&nbsp;</p>
<p><a href="http://www.randypatterson.com/images/Gettingareferencetothecurrentunitycontai_B90C/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="424" alt="image" src="http://www.randypatterson.com/images/Gettingareferencetothecurrentunitycontai_B90C/image_thumb.png" width="698" border="0"></a> </p>
<p><font size="3"></font>&nbsp;</p>
<p>&nbsp;<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2frandypatterson.com%2f2008%2f03%2f30%2fLazyInstantiationWithUnityApplicationBlock.aspx"><img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2frandypatterson.com%2f2008%2f03%2f30%2fLazyInstantiationWithUnityApplicationBlock.aspx" border="0"></a></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/&amp;title=Lazy+Instantiation+with+Unity+Application+Block" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/&amp;title=Lazy+Instantiation+with+Unity+Application+Block" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dotnetkicks.com/kick/?url=http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/&amp;title=Lazy+Instantiation+with+Unity+Application+Block" rel="nofollow" title="Add to&nbsp;DotNetKicks"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/dotnetkicks.png" title="Add to&nbsp;DotNetKicks" alt="Add to&nbsp;DotNetKicks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Lazy+Instantiation+with+Unity+Application+Block&amp;url=http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/&amp;title=Lazy+Instantiation+with+Unity+Application+Block" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/&amp;title=Lazy+Instantiation+with+Unity+Application+Block" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/&amp;title=Lazy+Instantiation+with+Unity+Application+Block" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/&amp;title=Lazy+Instantiation+with+Unity+Application+Block" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/&amp;title=Lazy+Instantiation+with+Unity+Application+Block" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Lazy+Instantiation+with+Unity+Application+Block+@+http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/&amp;t=Lazy+Instantiation+with+Unity+Application+Block" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://RandyPatterson.com/index.php/2008/03/30/lazy-instantiation-with-unity-application-block/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MSDN Article on Dependency Injection</title>
		<link>http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/</link>
		<comments>http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 04:16:10 +0000</pubDate>
		<dc:creator>randypatterson</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[IoC]]></category>

		<guid isPermaLink="false">http://localhost/2008/03/24/MSDNArticleOnDependencyInjection.aspx</guid>
		<description><![CDATA[Nice article posted by MSDN Magazine on Dependency Injection written by James Kovacs.&#160; Coincides nicely with my Presentation on Unity Application Block at the Orlando Code Camp


Bookmark It




















]]></description>
			<content:encoded><![CDATA[<p>Nice article posted by <a href="http://msdn2.microsoft.com/en-us/magazine/cc337885.aspx" target="_blank">MSDN Magazine on Dependency Injection</a> written by <a href="http://codebetter.com/blogs/james.kovacs/default.aspx" target="_blank">James Kovacs</a>.&nbsp; Coincides nicely with my <a href="http://randypatterson.com/2008/03/23/OrlandoCodeCampSlidesAndSampleCode.aspx" target="_blank">Presentation on Unity Application Block</a> at the Orlando Code Camp</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/&amp;title=MSDN+Article+on+Dependency+Injection" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/&amp;title=MSDN+Article+on+Dependency+Injection" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dotnetkicks.com/kick/?url=http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/&amp;title=MSDN+Article+on+Dependency+Injection" rel="nofollow" title="Add to&nbsp;DotNetKicks"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/dotnetkicks.png" title="Add to&nbsp;DotNetKicks" alt="Add to&nbsp;DotNetKicks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=MSDN+Article+on+Dependency+Injection&amp;url=http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/&amp;title=MSDN+Article+on+Dependency+Injection" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/&amp;title=MSDN+Article+on+Dependency+Injection" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/&amp;title=MSDN+Article+on+Dependency+Injection" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/&amp;title=MSDN+Article+on+Dependency+Injection" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/&amp;title=MSDN+Article+on+Dependency+Injection" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+MSDN+Article+on+Dependency+Injection+@+http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/&amp;t=MSDN+Article+on+Dependency+Injection" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://RandyPatterson.com/index.php/2008/03/24/msdn-article-on-dependency-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Orlando Code Camp slides and sample code</title>
		<link>http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/</link>
		<comments>http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 16:29:59 +0000</pubDate>
		<dc:creator>randypatterson</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://localhost/2008/03/23/OrlandoCodeCampSlidesAndSampleCode.aspx</guid>
		<description><![CDATA[The Orlando Code Camp was a huge success.&#160; Lots of great sessions and talented speakers. A special thanks goes out to Shawn Weisfeld of the Orlando .NET Users Group and Roy Lawson of the Lakeland Users Group, as well as the many other volunteers and speakers.
 Below, I&#8217;ve posted my Power Point slides and code [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.orlandocodecamp.com/default.aspx" target="_blank">Orlando Code Camp</a> was a huge success.&nbsp; Lots of great sessions and talented speakers. A special thanks goes out to <a href="http://www.ShawnWeisfeld.com" target="_blank">Shawn Weisfeld</a> of the <a href="http://onetug.net/default.aspx" target="_blank">Orlando .NET Users Group</a> and <a href="http://www.cfdotnet.org/About/tabid/61/Default.aspx" target="_blank">Roy Lawson</a> of the <a href="http://www.cfdotnet.org/" target="_blank">Lakeland Users Group</a>, as well as the many other volunteers and speakers.</p>
<p> Below, I&#8217;ve posted my Power Point slides and code samples for both my sessions at the Code Camp.</p>
<p><font size="4"></font>&nbsp;</p>
<p><font size="4">The Unity Application Block</font></p>
<p><iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-a368b40efafbe8fa.skydrive.live.com/embedrowdetail.aspx/Orlando%20Code%20Camp/Unity%20Application%20Block.zip" frameborder="0" scrolling="no"></iframe></p>
<p><font size="4">Beginning Test Driven Development</font></p>
<p><iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-a368b40efafbe8fa.skydrive.live.com/embedrowdetail.aspx/Orlando%20Code%20Camp/Beginning%20TDD.zip" frameborder="0" scrolling="no"></iframe></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/&amp;title=Orlando+Code+Camp+slides+and+sample+code" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/&amp;title=Orlando+Code+Camp+slides+and+sample+code" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dotnetkicks.com/kick/?url=http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/&amp;title=Orlando+Code+Camp+slides+and+sample+code" rel="nofollow" title="Add to&nbsp;DotNetKicks"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/dotnetkicks.png" title="Add to&nbsp;DotNetKicks" alt="Add to&nbsp;DotNetKicks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Orlando+Code+Camp+slides+and+sample+code&amp;url=http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/&amp;title=Orlando+Code+Camp+slides+and+sample+code" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/&amp;title=Orlando+Code+Camp+slides+and+sample+code" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/&amp;title=Orlando+Code+Camp+slides+and+sample+code" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/&amp;title=Orlando+Code+Camp+slides+and+sample+code" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/&amp;title=Orlando+Code+Camp+slides+and+sample+code" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Orlando+Code+Camp+slides+and+sample+code+@+http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/&amp;t=Orlando+Code+Camp+slides+and+sample+code" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://RandyPatterson.com/index.php/2008/03/23/orlando-code-camp-slides-and-sample-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to design a Fluent Interface</title>
		<link>http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/</link>
		<comments>http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/#comments</comments>
		<pubDate>Wed, 26 Sep 2007 17:25:09 +0000</pubDate>
		<dc:creator>randypatterson</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://localhost/2007/09/26/HowToDesignAFluentInterface.aspx</guid>
		<description><![CDATA[Martin Fowler coined the term &#8220;FluentInterface&#8221; to describe objects that expose an interface that flows, and is designed to be readable and concise.&#160; The cost of this fluency is additional effort required to design the interface for your object and the slight increase in complexity.&#160; These types of interfaces are often utilized to create configurations [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Martin_Fowler" target="_blank">Martin Fowler</a> coined the term &#8220;<a href="http://martinfowler.com/bliki/FluentInterface.html" target="_blank">FluentInterface</a>&#8221; to describe objects that expose an interface that <em>flows, </em>and is designed to be readable and concise.&nbsp; The cost of this fluency is additional effort required to design the interface for your object and the slight increase in complexity.&nbsp; These types of interfaces are often utilized to create configurations for your objects but can progress into an internal <a href="http://martinfowler.com/bliki/DomainSpecificLanguage.html" target="_blank">Domain Specific Language</a> or <span class="acronym" title="Domain Specific Language">DSL</span>.</p>
<p><em>Configuration Fluent Interface Example: (sometimes called Method Chaining</em>) </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:58ea0d9a-72a2-4290-8cc9-ff27000ce650" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #000000; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#000000;color:#fddf39">Order</span><br />
<span style="background:#000000;color:#fddf39">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">AddFreeShipping</span><span style="background:#000000;color:#ffffff">()</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;.</span><span style="background:#000000;color:#fddf39">IncludeItem</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#8acccf">10</span><span style="background:#000000;color:#ffffff">)</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;.</span><span style="background:#000000;color:#fddf39">SetQuantity</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#8acccf">2</span><span style="background:#000000;color:#ffffff">);</span></div>
</div>
</div>
<p><em>DSL Fluent Interface Example:&nbsp; (<a href="http://ayende.com/projects/rhino-mocks.aspx" target="_blank">Rhino Mocks</a>)</em>&nbsp;</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5997c476-765b-4a20-9a63-8bb7bd84a825" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #000000; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#000000;color:#fddf39">Expect</span><br />
<span style="background:#000000;color:#fddf39">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">Call</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#fddf39">entityMock</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">GetID</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#8acccf">12</span><span style="background:#000000;color:#ffffff">))</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;.</span><span style="background:#000000;color:#fddf39">IgnoreArguments</span><span style="background:#000000;color:#ffffff">()</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;.</span><span style="background:#000000;color:#fddf39">Repeat</span><br />
<span style="background:#000000;color:#fddf39">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">Once</span><span style="background:#000000;color:#ffffff">()</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;.</span><span style="background:#000000;color:#fddf39">Return</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#fddf39">entityDataSet</span><span style="background:#000000;color:#ffffff">);</span></div>
</div>
</div>
<p>
<h3>Show me the Code</h3>
</p>
<p><br/></p>
<p>Fluent interfaces are best explained by showing some code examples, so I&#8217;ll take the rather prosaic <em>Person</em> object and create a fluent interface for it.&nbsp;&nbsp;&nbsp; </p>
<p><em>Take a common Person object and write some code to instantiate and Initialize the object</em></p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:11a747a8-a7f7-4cb2-b0e3-0dd51b7a4a29" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #000000; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">class</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#b3b300">Person</span><br />
<span style="background:#000000;color:#b3b300">{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">private</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_firstName</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">private</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_lastName</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">private</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">int</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_age</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">bool</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_isActive</span><span style="background:#000000;color:#ffffff">;</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">Person</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">firstName</span><span style="background:#000000;color:#ffffff">, </span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">lastName</span><span style="background:#000000;color:#ffffff">, </span><span style="background:#000000;color:#ff8000">int</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">age</span><span style="background:#000000;color:#ffffff">, </span><span style="background:#000000;color:#ff8000">bool</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">isActive</span><span style="background:#000000;color:#ffffff">)</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_firstName</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#fddf39">firstName</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_lastName</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#fddf39">lastName</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_age</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#fddf39">age</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_isActive</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#fddf39">isActive</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">FirstName</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">get</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_firstName</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">set</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#fddf39">_firstName</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">value</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">LastName</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">get</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_lastName</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">set</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#fddf39">_lastName</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">value</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">int</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">Age</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">get</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_age</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">set</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#fddf39">_age</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">value</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">bool</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">IsActive</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">get</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_isActive</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">set</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#fddf39">_isActive</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">value</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span><br />
<span style="background:#000000;color:#ffffff">}</span></div>
</div>
</div>
<p>This is a common pattern where the constructor is used to quickly set the properties of the class.&nbsp; The initialization code would look something like this. </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c37962ad-6f91-4783-b54b-bfdca548780d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #000000; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#000000;color:#fddf39">Person</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">person</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">new</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">Person</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#00ff00">&quot;Frank&quot;</span><span style="background:#000000;color:#ffffff">, </span><span style="background:#000000;color:#00ff00">&quot;Pat&quot;</span><span style="background:#000000;color:#ffffff">, </span><span style="background:#000000;color:#8acccf">30</span><span style="background:#000000;color:#ffffff">, </span><span style="background:#000000;color:#ff8000">true</span><span style="background:#000000;color:#ffffff">); </span></div>
</div>
</div>
<p>Although this code is concise it is not very readable. Is &#8220;Frank&#8221; the first name or the last name? What does the value <font color="#0000ff">true</font> represent? The readability issue becomes more problematic as the number of construction parameters increase.&nbsp; One solution, and the point of this post, is to write a <a href="http://martinfowler.com/bliki/FluentInterface.html" target="_blank">Fluent Interface</a> for our Person class.&nbsp; The idea here is to allow each property to be set through a method call and then have that method return a reference to itself so you can continue on with next method call (often called method chaining). </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1ea32156-e0cd-43c0-9ad6-9f3651240b50" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #000000; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#000000;color:#fddf39">person</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">SetLastName</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#00ff00">&quot;Frank&quot;</span><span style="background:#000000;color:#ffffff">).</span><span style="background:#000000;color:#fddf39">SetFirstName</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#00ff00">&quot;Pat&quot;</span><span style="background:#000000;color:#ffffff">);</span></div>
</div>
</div>
<p>This makes our code concise and far easier to read, we now know that &#8220;Frank&#8221; is the last name.&nbsp; However, an obvious issue with this pattern is that we are now cluttering up our class with methods that, when taken out of context, make little sense.&nbsp; We have a <font color="#0000ff">FirstName</font> property and a <font color="#0000ff">SetFirstName</font> method defined on our class that obfuscates the intent. A better approach is to create an internal class that is accessed through a <font color="#0000ff">Set </font>property and exposes only the <a href="http://martinfowler.com/bliki/FluentInterface.html" target="_blank">Fluent Interface</a>.</p>
<p>&nbsp;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:41e90882-d9b6-4b3f-973e-7906d55217f2" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #000000; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">class</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#b3b300">Person</span><br />
<span style="background:#000000;color:#b3b300">{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">Person</span><span style="background:#000000;color:#ffffff">()</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_set</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">new</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">PersonFluentInterface</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#ff8000">this</span><span style="background:#000000;color:#ffffff">);</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">private</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_firstName</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">private</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_LastName</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">private</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">int</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_age</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">private</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">readonly</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">PersonFluentInterface</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_set</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">private</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">bool</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_isActive</span><span style="background:#000000;color:#ffffff">;</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">PersonFluentInterface</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">Set</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">get</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_set</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">FirstName</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">get</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_firstName</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">set</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#fddf39">_firstName</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">value</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">LastName</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">get</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_LastName</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">set</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#fddf39">_LastName</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">value</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">int</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">Age</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">get</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_age</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">set</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#fddf39">_age</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">value</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">bool</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">IsActive</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">get</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_isActive</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">set</span><span style="background:#000000;color:#ffffff"> { </span><span style="background:#000000;color:#fddf39">_isActive</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">value</span><span style="background:#000000;color:#ffffff">; }</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">class</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#b3b300">PersonFluentInterface</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">private</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">readonly</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">Person</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">_person</span><span style="background:#000000;color:#ffffff">;</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">PersonFluentInterface</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#fddf39">Person</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">person</span><span style="background:#000000;color:#ffffff">)</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_person</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#fddf39">person</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">PersonFluentInterface</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">FirstName</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">firstName</span><span style="background:#000000;color:#ffffff">)</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_person</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">FirstName</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#fddf39">firstName</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">this</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">PersonFluentInterface</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">LastName</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#ff8000">string</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">lastName</span><span style="background:#000000;color:#ffffff">)</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_person</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">LastName</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#fddf39">lastName</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">this</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">PersonFluentInterface</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">Age</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#ff8000">int</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">age</span><span style="background:#000000;color:#ffffff">)</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_person</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">Age</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#fddf39">age</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">this</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">PersonFluentInterface</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">IsActive</span><span style="background:#000000;color:#ffffff">()</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_person</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">IsActive</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">true</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">this</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</span></p>
<p><span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">public</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">PersonFluentInterface</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">IsNotActive</span><span style="background:#000000;color:#ffffff">()</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#fddf39">_person</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">IsActive</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">false</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="background:#000000;color:#ff8000">return</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#ff8000">this</span><span style="background:#000000;color:#ffffff">;</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</span><br />
<span style="background:#000000;color:#ffffff">&#160;&#160;&#160;&#160;}</span><br />
<span style="background:#000000;color:#ffffff">}</span></div>
</div>
</div>
<p>Now the code is clean, concise and quite readable.</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6fd6fdca-132d-42e3-ab8e-a0e426c387df" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #000000; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#000000;color:#fddf39">Person</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">person</span><span style="background:#000000;color:#ffffff"> = </span><span style="background:#000000;color:#ff8000">new</span><span style="background:#000000;color:#ffffff"> </span><span style="background:#000000;color:#fddf39">Person</span><span style="background:#000000;color:#ffffff">();</span><br />
<span style="background:#000000;color:#fddf39">person</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">Set</span><span style="background:#000000;color:#ffffff">.</span><span style="background:#000000;color:#fddf39">FirstName</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#00ff00">&quot;Pat&quot;</span><span style="background:#000000;color:#ffffff">).</span><span style="background:#000000;color:#fddf39">LastName</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#00ff00">&quot;Frank&quot;</span><span style="background:#000000;color:#ffffff">).</span><span style="background:#000000;color:#fddf39">Age</span><span style="background:#000000;color:#ffffff">(</span><span style="background:#000000;color:#8acccf">30</span><span style="background:#000000;color:#ffffff">).</span><span style="background:#000000;color:#fddf39">IsActive</span><span style="background:#000000;color:#ffffff">();</span></div>
</div>
</div>
<p>&nbsp;</p>
<h3>Conclusion</h3>
<p>&nbsp;</p>
<p>This pattern for fluent interfaces is often seen in object configuration and setup.&nbsp; It&#8217;s fairly easy to design and the objects configuration options are readily discoverable using intellisense.&nbsp; As the complexity of an objects setup increased, a fluent interface becomes a more attractive option to ease the initialization burden. </p>
<p>&nbsp;
<p>&nbsp;</p>
</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://randypatterson.com/2007/09/26/HowToDesignAFluentInterface.aspx"><img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://randypatterson.com/2007/09/26/HowToDesignAFluentInterface.aspx&amp;border=&amp;fgcolor=&amp;bgcolor=&amp;cfgcolor=&amp;cbgcolor="></a></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/&amp;title=How+to+design+a+Fluent+Interface" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/&amp;title=How+to+design+a+Fluent+Interface" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dotnetkicks.com/kick/?url=http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/&amp;title=How+to+design+a+Fluent+Interface" rel="nofollow" title="Add to&nbsp;DotNetKicks"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/dotnetkicks.png" title="Add to&nbsp;DotNetKicks" alt="Add to&nbsp;DotNetKicks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=How+to+design+a+Fluent+Interface&amp;url=http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/&amp;title=How+to+design+a+Fluent+Interface" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/&amp;title=How+to+design+a+Fluent+Interface" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/&amp;title=How+to+design+a+Fluent+Interface" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/&amp;title=How+to+design+a+Fluent+Interface" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/&amp;title=How+to+design+a+Fluent+Interface" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+How+to+design+a+Fluent+Interface+@+http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/&amp;t=How+to+design+a+Fluent+Interface" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://RandyPatterson.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://RandyPatterson.com/index.php/2007/09/26/how-to-design-a-fluent-interface/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
