<?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:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Ray Houston</title><link>http://www.lostechies.com/blogs/rhouston/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/RayHoustonBlog" type="application/rss+xml" /><item><title>Fluent Silverlight - Auto Wiring INotifyPropertyChanged</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/AVfDqEwo7Yg/fluent-silverlight-auto-wiring-inotifypropertychanged.aspx</link><pubDate>Wed, 03 Jun 2009 03:13:58 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:21469</guid><dc:creator>Ray Houston</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=21469</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2009/06/02/fluent-silverlight-auto-wiring-inotifypropertychanged.aspx#comments</comments><description>&lt;p&gt;In &lt;a href="http://www.lostechies.com/blogs/gabrielschenker/archive/2009/06/02/fluent-silverlight-part-2-binding-properties.aspx"&gt;Gabriel&amp;#39;s introductory post for Fluent Silverlight&lt;/a&gt;, he showed that the code typically associated with implementing INotifyPropertyChanged can be reduced to a simple auto property. This can really improve the clarity of a large class as well as save some typing. I&amp;#39;m going to show you how to get it setup.&lt;/p&gt; &lt;h3&gt;INotifyPropertyChanged&lt;/h3&gt; &lt;p&gt;First lets talk a little about normal INotifyPropertyChanged. This is an interface that is typically implemented on a ViewModel that you wish to participate in two way data binding between itself and some sort of DependencyProperty which typically lives on a control. The interface declaration looks like:&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; INotifyPropertyChanged
{
    &lt;span style="color:#0000ff;"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;
}
&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;The PropertyChanged event on this interface is used to notify the control of any updates of properties that happen in your ViewModel so that the control can be refreshed with any updated data. Without the use of this interface, your updates will end up only being one way. Which means that the ViewModel will be updated with any changes from the control, but the control will not be updated with the changes from the ViewModel. A typical implementation may look like:&lt;/div&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; MyViewModel : INotifyPropertyChanged
{
    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; name;
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; Name
    {
        get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; name; }
        set
        {
            &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;value&lt;/span&gt; == name) &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt;; 
            name = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;;
            OnPropertyChanged(&lt;span style="color:#006080;"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;);
        }
    }

    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; age;
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; Age
    {
        get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; age; }
        set
        {
            &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;value&lt;/span&gt; == age) &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt;;
            age = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;;
            OnPropertyChanged(&lt;span style="color:#006080;"&gt;&amp;quot;Age&amp;quot;&lt;/span&gt;);
        }
    }

    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;

    &lt;span style="color:#0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; OnPropertyChanged(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; propertyName)
    {
        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (PropertyChanged != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)
            PropertyChanged(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; PropertyChangedEventArgs(propertyName));
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;As you can see, it makes for a lot of noise. Also make note of the &amp;quot;Name&amp;quot; and &amp;quot;Age&amp;quot; strings which are not very refactor friendly. &lt;/div&gt;
&lt;h3&gt;IAutoNotifyPropertyChanged&lt;/h3&gt;
&lt;p&gt;We got to thinking that if we could intercept the changes to the properties (AOP), then we could automatically throw the PropertyChanged event. One way to do this is to use Castle.DynamicProxy (the Silverlight edition). DynamicProxy allows us to create a runtime generated subclass of our ViewModel. The generated subclass allows interception of any virtual member where we can chose to do what we please. To get it all started, we needed an interface that would allow us to trigger the event:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; IAutoNotifyPropertyChanged : INotifyPropertyChanged
{
    &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; OnPropertyChanged(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; propertyName);
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next we updated our ViewModel to implement the new IAutoNotifyPropertyChanged interface and removed all the extras:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; MyViewModel : IAutoNotifyPropertyChanged
{
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;virtual&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; Name { get; set; }
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;virtual&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; Age { get; set; }

    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;

    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; OnPropertyChanged(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; propertyName)
    {
        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (PropertyChanged != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)
            PropertyChanged(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; PropertyChangedEventArgs(propertyName));
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see, there is a lot less noise here and we don&amp;#39;t have the magic strings for the property names laying around. Also note that we made the properties virtual so that they can be intercepted. To actually make the auto wiring work, we have to create an instance of the ViewModel class (actually it&amp;#39;s a generated subclass) using our AutoNotifyPropertyChangedProxyCreator. I&amp;#39;m not sure if we&amp;#39;ll stick with that name, but it will do for now. Take a look at the following little test:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;[TestFixture]
&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; when_creating_viewmodel_with_creator
{
    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; MyViewModel model;
    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; lastPropChanged;

    [SetUp]
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetUp()
    {
        model = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; AutoNotifyPropertyChangedProxyCreator().Create&amp;lt;MyViewModel&amp;gt;();

        model.PropertyChanged += (s, e) =&amp;gt; lastPropChanged = e.PropertyName;

        lastPropChanged = &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;;
    }

    [Test]
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; should_send_property_changed_for_given_property()
    {
        model.Name = &lt;span style="color:#006080;"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;;

        Assert.That(lastPropChanged, Is.EqualTo(&lt;span style="color:#006080;"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;));
        Assert.That(model.Name, Is.EqualTo(&lt;span style="color:#006080;"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;));
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Because the proxy is a subclass, we can treat it as it&amp;#39;s original type MyViewModel. As the Name property changes, it fires the PropertyChanged event which is wired to update the lastPropChanged field.&lt;/p&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
&lt;p&gt;INotifyPropertyChanged is a handy interface for doing two way data binding but it causes a lot of extra noise in your classes. In &lt;a href="http://code.google.com/p/fluent-silverlight/"&gt;Fluent Silverlight&lt;/a&gt;, we have introduced the IAutoNotifyPropertyChanged interface which is used in conjunction with AutoNotifyPropertyChangedProxyCreator which uses Dynamic Proxy to intercept the calls and auto throw the PropertyChanged event. This allowed us to reduce the noise and completely remove the magic strings typically associated with standard INotifyPropertyChanged. &lt;/p&gt;
&lt;p&gt;In a future post I&amp;#39;ll demonstrate how you can do other things with this such as ignore certain properties, tap into the interception to execute methods and have an IoC container handle the proxy creation.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:82fad389-0210-497e-89a9-e7387221e536" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Fluent%20Silverlight" rel="tag"&gt;Fluent Silverlight&lt;/a&gt;,&lt;a href="http://technorati.com/tags/INotifyPropertyChanged" rel="tag"&gt;INotifyPropertyChanged&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Silverlight" rel="tag"&gt;Silverlight&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=21469" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RayHoustonBlog?a=AVfDqEwo7Yg:pw0-uiYD9eo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RayHoustonBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/AVfDqEwo7Yg" height="1" width="1"/&gt;</description><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/INotifyPropertyChanged/default.aspx">INotifyPropertyChanged</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/Fluent+Silverlight/default.aspx">Fluent Silverlight</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/MVVM/default.aspx">MVVM</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/Dynamic+Proxy/default.aspx">Dynamic Proxy</category><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2009/06/02/fluent-silverlight-auto-wiring-inotifypropertychanged.aspx</feedburner:origLink></item><item><title>Simple Code Navigation with ReSharper</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/ByV15dFblcw/simple-code-navigation-with-resharper.aspx</link><pubDate>Sat, 11 Apr 2009 01:20:37 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:20248</guid><dc:creator>Ray Houston</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=20248</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2009/04/10/simple-code-navigation-with-resharper.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://screencasts.lostechies.com/screencasts/rhouston/NavWithResharper/NavWithResharper.htm"&gt;Here&amp;#39;s a quick 5 minute screen cast&lt;/a&gt; that demonstrates how you can use ReSharper to get where you want to be in your code. If you haven&amp;#39;t tried ReSharper yet, I highly recommend that you download the free trial and give it a spin.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e3c84b5a-3110-45b3-8f17-bc055ac92c93" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/ReSharper" rel="tag"&gt;ReSharper&lt;/a&gt;,&lt;a href="http://technorati.com/tags/PabloTV" rel="tag"&gt;PabloTV&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=20248" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RayHoustonBlog?a=ByV15dFblcw:8fZSA-JXhkE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RayHoustonBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/ByV15dFblcw" height="1" width="1"/&gt;</description><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/ReSharper/default.aspx">ReSharper</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/Tools/default.aspx">Tools</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/.NET/default.aspx">.NET</category><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2009/04/10/simple-code-navigation-with-resharper.aspx</feedburner:origLink></item><item><title>Don't Waste The Time We Have Now</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/K67JbSEmjCM/don-t-waste-the-time-we-have-now.aspx</link><pubDate>Sun, 15 Mar 2009 22:47:56 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:19894</guid><dc:creator>Ray Houston</dc:creator><slash:comments>7</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=19894</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2009/03/15/don-t-waste-the-time-we-have-now.aspx#comments</comments><description>&lt;p&gt;I almost titled this &amp;quot;Get Things Done&amp;quot; but this post is not about how to do things. This post is about minimizing waste associated with distractions from non work related activities. I&amp;#39;m talking about things like Instant Messenger, Twitter, Skype, Facebook, personal phone calls, texting or anything else that is a distraction.&lt;/p&gt;
&lt;p&gt;Some of the online tools can be used for work related activities (and I do used them), but they can also be major productivity killers. I bet that 90% of what happens on these things is noise. I don&amp;#39;t have any statistics to back that up, but from my own experiences, what happens on there is mostly waste. For myself, I have enough work related distractions without piling on extras. You don&amp;#39;t notice how much time you actually waste until you get so busy that any unnecessary distraction becomes a painful thing.&lt;/p&gt;
&lt;p&gt;If you&amp;#39;ve had the opportunity to do some real pair programming, then you can appreciate minimizing distractions. One of the reason pair programming works, is that it keeps both parties engaged in the work. Even a simple phone call or text message to either party is a distraction. It actually even feels rude. After a good day of pairing, you feel exhausted because you put in a real day&amp;#39;s work. You were engaged the entire time. Why don&amp;#39;t we hold ourselves to the same standards when we are programming solo?&lt;/p&gt;
&lt;p&gt;Don&amp;#39;t get me wrong. I&amp;#39;m not saying that we shouldn&amp;#39;t take breaks and have our minds think about other things once in awhile. The fact is that we&amp;#39;re going to have non worked related distractions. The real point of this post is to remind everyone that in economic times like these, we cannot afford to waste the time we have now. If a company of 100 people waste 20 minutes a day on non worked related activities, then that is over a man week that has been wasted within that day. Wasted, gone, vanished, can&amp;#39;t get it back. The time you waste today, may mean someone&amp;#39;s job tomorrow (if not your own).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=19894" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RayHoustonBlog?a=K67JbSEmjCM:xOVbTuDzns0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RayHoustonBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/K67JbSEmjCM" height="1" width="1"/&gt;</description><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2009/03/15/don-t-waste-the-time-we-have-now.aspx</feedburner:origLink></item><item><title>Pablo welcomes Gabriel Schenker</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/mmnjCqua0h8/pablo-welcomes-gabriel-schenker.aspx</link><pubDate>Sat, 10 Jan 2009 17:00:52 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:12791</guid><dc:creator>Ray Houston</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=12791</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2009/01/10/pablo-welcomes-gabriel-schenker.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;m happy to announce that Gabriel Schenker has accepted an invitation to join Los Techies. You may know Gabriel as the man behind the &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/Default.aspx"&gt;NHibernate FAQ Blog&lt;/a&gt; or contributor to many of the software related community lists. He is an expert in &lt;a href="http://www.google.com/url?sa=U&amp;amp;start=1&amp;amp;q=http://en.wikipedia.org/wiki/Didactics&amp;amp;ei=v91oSfGDIJSaNZKqzZ4H&amp;amp;usg=AFQjCNG3vYp1hxeIf7AK8ADaXhZPu3774g"&gt;didactics&lt;/a&gt; and methodology. He is very passionate about software development and the software community.&lt;/p&gt;
&lt;p&gt;Look for his LosTechies posts at &lt;a href="http://gabrielschenker.lostechies.com"&gt;http://gabrielschenker.lostechies.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Welcome Gabriel!!!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=12791" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=qqxSZCNe"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/mmnjCqua0h8" height="1" width="1"/&gt;</description><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/Members/default.aspx">Members</category><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2009/01/10/pablo-welcomes-gabriel-schenker.aspx</feedburner:origLink></item><item><title>PTOM: The Composite Design Pattern</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/SwNk_zhe0WI/ptom-the-composite-design-pattern.aspx</link><pubDate>Tue, 18 Nov 2008 02:07:28 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:6497</guid><dc:creator>Ray Houston</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=6497</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/11/17/ptom-the-composite-design-pattern.aspx#comments</comments><description>&lt;h2&gt;The Composite Design Pattern&lt;/h2&gt; &lt;p&gt;This post talks about the Composite Design Pattern and is part of &lt;a href="http://www.lostechies.com/blogs/rhouston/archive/2008/11/05/pablo-s-topic-of-the-month-november-design-patterns.aspx"&gt;Pablo&amp;#39;s Topic of the Month - November: Design Patterns&lt;/a&gt;. A Composite is a tree structure where each node can be represented as a common type so that they can be acted on in a consistent manner, regardless of their concrete implementations. This allows a consumer of the composite to avoid the complexity of having to distinguish the objects individually. I believe that the posts for PTOM are going to centered around a coffee shop, but I&amp;#39;m having a difficult time thinking of a good composite example around that, so let&amp;#39;s say I&amp;#39;m building coffee machines instead.&lt;/p&gt; &lt;p&gt;Lets pretend that I have a model of a coffee machine and all of its parts. Many of the parts are logical and are made up of only child parts. I might have a class that looks something like the following (simplistically implemented for example purposes):&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; CoffeeMachine
{
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; FluxCapacitor FluxCapacitor { get; set; }
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; PowerCord PowerCord { get; set; }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;Lets say FluxCapacitor is a composite part made up of child parts and those child parts may have their own child parts. I want to build a class that allows me to output all the given parts for a machine, but I don&amp;#39;t want my part list generator to know about each specific details of the machine or any of its specific parts. If I did couple the list generator to those implementations, that would force me to modify the list generator every time we added or changed a part, which would be a violation of &lt;a href="http://www.lostechies.com/blogs/joe_ocampo/archive/2008/03/21/ptom-the-open-closed-principle.aspx"&gt;OCP&lt;/a&gt;. We can solve this problem by creating an interface that lets us traverse our structure as a composite.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; IPart
{
    IEnumerable&amp;lt;IPart&amp;gt; GetChildParts();
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You will notice that the IPart returns child instances of other IParts. This gives us a recursive structure and lets us act on that structure as a composite. By implementing this interface on all of our parts, when can then walk the hierarchy and perform operations without knowing the details of each implementation. We can implement this on our CoffeeMachine and our other parts like the following:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; CoffeeMachine : IPart
{
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; FluxCapacitor FluxCapacitor { get; set; }
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; PowerCord PowerCord { get; set; }

    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; IEnumerable&amp;lt;IPart&amp;gt; GetChildParts()
    {
        &lt;span style="color:#0000ff;"&gt;yield&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; FluxCapacitor;
        &lt;span style="color:#0000ff;"&gt;yield&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; PowerCord;
    }
}

&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; FluxCapacitor : IPart
{
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; Switch Switch { get; set; }
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; PowerBooster PowerBooster { get; set; }

    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; IEnumerable&amp;lt;IPart&amp;gt; GetChildParts()
    {
        &lt;span style="color:#0000ff;"&gt;yield&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; Switch;
        &lt;span style="color:#0000ff;"&gt;yield&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; PowerBooster;
    } 
}

&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; PowerCord : IPart
{
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; IEnumerable&amp;lt;IPart&amp;gt; GetChildParts()
    {
        &lt;span style="color:#0000ff;"&gt;yield&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;break&lt;/span&gt;;
    }        
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now we can easily build a part list generator that uses a recursive method to walk through the hierarchy and outputs the names of the parts.&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; PartListGenerator
{
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; OutpAllParts(IPart part, TextWriter textWriter)
    {
        OuputAllPartsByLevel(part, textWriter, 0);    
    }

    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; OuputAllPartsByLevel(IPart part, TextWriter textWriter, &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; level)
    {
        textWriter.WriteLine(&lt;span style="color:#006080;"&gt;&amp;quot;{0}{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;(&lt;span style="color:#006080;"&gt;&amp;#39;\t&amp;#39;&lt;/span&gt;, level), part.GetType().Name);

        &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; (var childPart &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; part.GetChildParts())
        {
            OuputAllPartsByLevel(childPart, textWriter, level + 1);
        }
    }
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;By running our CoffeeMachine through this class, we end up with something similar to the following output:&lt;/p&gt;
&lt;p&gt;CoffeeMachine&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FluxCapacitor&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Switch&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PowerBooster&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PowerCord 
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;You may have noticed that we have the GetChildParts() method implemented on the leaf parts as well (see PowerCord). This may be a slight violation of &lt;a href="http://www.lostechies.com/blogs/rhouston/archive/2008/03/14/ptom-the-interface-segregation-principle.aspx"&gt;ISP&lt;/a&gt;, but it is side effect free and it does not violate &lt;a href="http://www.lostechies.com/blogs/chad_myers/archive/2008/03/09/ptom-the-liskov-substitution-principle.aspx"&gt;LSP&lt;/a&gt; therefor it does not bother me too much. In the real world, IPart would probably have other functionality and you could split out the GetChildParts() into a separate interface such as ICompositePart which would only be implemented by non leafs. This would require the PartListGenerator to know about IParts and ICompositeParts which may or may not be desirable. It&amp;#39;s really a trade off here as to what makes the most sense for your needs.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;There are several variations of the Composite Design Pattern and my example can probably be considered one of them. The Composite can also be combined with other patterns such as the Specification or Command patterns. You can find lots of other examples on the web and in &lt;a href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=sr_11_1?ie=UTF8&amp;amp;qid=1207103933&amp;amp;sr=11-1"&gt;Design Patterns : Elements of Reusable Object-Oriented Software&lt;/a&gt;. I recommend picking up that book for more information on the Composite and many other must know patterns.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=6497" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=xf0wlggj"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/SwNk_zhe0WI" height="1" width="1"/&gt;</description><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/PTOM/default.aspx">PTOM</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/Patterns/default.aspx">Patterns</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/Principles/default.aspx">Principles</category><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/11/17/ptom-the-composite-design-pattern.aspx</feedburner:origLink></item><item><title>Pablo's Topic of the Month - November: Design Patterns</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/j4Dyx4XARSQ/pablo-s-topic-of-the-month-november-design-patterns.aspx</link><pubDate>Wed, 05 Nov 2008 10:57:13 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:5994</guid><dc:creator>Ray Houston</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=5994</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/11/05/pablo-s-topic-of-the-month-november-design-patterns.aspx#comments</comments><description>&lt;h3&gt;Pablo&amp;#39;s Topic of the Month - November: Design Patterns&lt;/h3&gt; &lt;p&gt;&lt;a href="http://www.lostechies.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/rhouston/image_5F00_5.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;margin:0px 0px 0px 5px;border-right-width:0px;" height="240" alt="image" src="http://www.lostechies.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/rhouston/image_5F00_thumb.png" width="240" align="right" border="0" /&gt;&lt;/a&gt; Back in April, we announced we would be doing a PTOM on Design Patterns. It turned out that April was a busy month for all of us and we didn&amp;#39;t live up to our announcement.&amp;nbsp; I think we&amp;#39;re going to claim it as a sad April fools joke. During the course of this month we will revisit our previous topic with the exception that the patterns will not just be patterns from &lt;a href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=sr_11_1?ie=UTF8&amp;amp;qid=1207103933&amp;amp;sr=11-1"&gt;&amp;#39;Design Patterns: Elements of Reusable Object-Oriented Software&amp;#39; (Addison-Wesley. ISBN 0-201-63361-2)&lt;/a&gt; , but from various sources which we believe are relevant to the types of programs being written today.&lt;/p&gt; &lt;p&gt;If you haven&amp;#39;t already, please consider subscribing to the Los Techies Main Feed so that you can see the various post from all the Los Techies bloggers.  &lt;p&gt;The main feed is here:&amp;nbsp; &lt;a href="http://feeds.feedburner.com/lostechies"&gt;http://feeds.feedburner.com/lostechies&lt;/a&gt;  &lt;h3&gt;What is a Design Pattern?&lt;/h3&gt; &lt;p&gt;A Design Pattern is exactly what it sounds like. It&amp;#39;s a design that can be applied over and over again, forming a pattern. The Wikipedia &lt;a href="http://en.wikipedia.org/wiki/Design_Patterns"&gt;page&lt;/a&gt; for Design Patterns describes one as&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;a general reusable solution to a commonly occurring problem in &lt;a href="http://en.wikipedia.org/wiki/Software_design"&gt;software design&lt;/a&gt;. A design pattern is not a finished design that can be transformed directly into &lt;a href="http://en.wikipedia.org/wiki/Code_%28computer_programming%29"&gt;code&lt;/a&gt;. It is a description or template for how to solve a problem that can be used in many different situations.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;By using Design Patterns, we can better standardize our designs makes them easier to understand.&amp;nbsp; Design Patterns give us a common vocabulary in which to use in communicating software designs. Without them, we would have a difficult time in explaining and documenting our ideas.&lt;/p&gt; &lt;h3&gt;Posts on Design Patterns&lt;/h3&gt; &lt;p&gt;We will update this area with links to the posts as they happen.&lt;/p&gt; &lt;h3&gt;&lt;a href="http://www.lostechies.com/blogs/sean_chambers/archive/2008/11/16/ptom-the-decorator-pattern.aspx"&gt;PTOM: The Decorator Pattern by Sean Chambers&lt;/a&gt;&lt;/h3&gt; &lt;h3&gt;&lt;a href="http://www.lostechies.com/blogs/rhouston/archive/2008/11/17/ptom-the-composite-design-pattern.aspx"&gt;PTOM: The Composite Pattern by Ray Houston&lt;/a&gt;&lt;/h3&gt; &lt;h3&gt;&lt;a href="http://www.lostechies.com/blogs/derickbailey/archive/2008/11/19/ptom-command-and-conquer-your-ui-coupling-problems.aspx"&gt;PTOM: Command and Conquer Your UI Coupling Problems by Derick Bailey&lt;/a&gt;&lt;/h3&gt; &lt;h3&gt;&lt;a href="http://www.lostechies.com/blogs/johnteague/archive/2008/11/25/ptom-bend-3rd-party-libraries-to-your-will-with-the-adapter-pattern.aspx"&gt;PTOM: Bend 3rd Party Libraries to Your Will With the Adapter Pattern by John Teague&lt;/a&gt;&lt;/h3&gt; &lt;h3&gt;&lt;a href="http://www.lostechies.com/blogs/derickbailey/archive/2008/11/26/ptom-descriptive-state-enumeration.aspx"&gt;PTOM: Descriptive State Enumeration by Derick Bailey&lt;/a&gt;&lt;/h3&gt; &lt;h3&gt;&lt;a href="http://www.lostechies.com/blogs/jason_meridth/archive/2008/11/30/ptom-november-2008-visitor-design-pattern.aspx"&gt;PTOM: Visitor Design Pattern by Jason Meridth&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:44e15592-062a-4ab3-8e85-b63537ac35f4" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/PTOM" rel="tag"&gt;PTOM&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Design%20Patterns" rel="tag"&gt;Design Patterns&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5994" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=1VqMdWLE"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/j4Dyx4XARSQ" height="1" width="1"/&gt;</description><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/PTOM/default.aspx">PTOM</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/Patterns/default.aspx">Patterns</category><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/Principles/default.aspx">Principles</category><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/11/05/pablo-s-topic-of-the-month-november-design-patterns.aspx</feedburner:origLink></item><item><title>Udi's SOA Class Made Me Smart</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/kKIP9lzmVBY/udi-s-soa-class-made-me-smart.aspx</link><pubDate>Sun, 26 Oct 2008 16:07:41 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:5624</guid><dc:creator>Ray Houston</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=5624</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/10/26/udi-s-soa-class-made-me-smart.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.lostechies.com/blogs/chris_patterson"&gt;Chris&lt;/a&gt; challenged me to write a post showing how smart I am after taking the class. ;) While I know that &amp;quot;made me smart&amp;quot; is completely unbelievable, I did manage learn a great deal.&lt;/p&gt; &lt;p&gt;I&amp;#39;m slow to getting around to this post, but little over a week ago I finished up &lt;a href="http://www.udidahan.com/"&gt;Udi Dahan&amp;#39;s&lt;/a&gt; week long class called &amp;quot;Advanced Distributed Systems Design using SOA &amp;amp; DDD&amp;quot;. As &lt;a href="http://codebetter.com/blogs/aaron.jensen/archive/2008/10/19/udi-dahan-s-soa-bootcamp.aspx"&gt;Aaron&lt;/a&gt; has already stated, it was awesome. The class was very well put together. The materials were clear and concise and Udi did a fantastic job presenting it. It was a good mixture of lecture, coding, and question and answer. I fully expected that I would be taking notes like crazy, but it was so well laid out that the only thing I wrote down the entire course was what I wanted for lunch. Udi provided us with all the lecture materials and everyone has access to all of the samples which are in the &lt;a href="http://www.nservicebus.com/"&gt;nServiceBus&lt;/a&gt; trunk.&lt;/p&gt; &lt;p&gt;Now I know why Udi is the &amp;quot;Software Simplist.&amp;quot; I was amazed to find that all the code and solutions were indeed very simple. Your day to day DDD code doesn&amp;#39;t change (if you&amp;#39;re doing it well). All the hard stuff is dealt with at the bus level. You as the architect need to know what&amp;#39;s going on so that you can apply the patterns appropriately, but a developer in the domain should not be writing code that deals with things like threading. If you are, you&amp;#39;re doing it wrong. The patterns that Udi presented keep things simple by isolating complexity so that it doesn&amp;#39;t creep into your day to day code. The domain code looks the same if it&amp;#39;s running in a single process or if it&amp;#39;s running in 100 processes.&lt;/p&gt; &lt;p&gt;Udi kept saying that the code is simple, but defining the right boundaries is the hard part. Often the questions we gave Udi were solved by diving deeper into the real business requirement and giving the business choices as to what their requirements really mean in terms of performance, latency, durability, etc. You get into trouble when you try to make a technical problem out of what should be a business decision.&lt;/p&gt; &lt;p&gt;Two great quotes from the lecture materials:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;Best practices have yet to catch up to &amp;quot;best thinking&amp;quot;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;Technology cannot solve all problems&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Good SOA is not about applying one single thing over and over again. It&amp;#39;s about knowing your requirements, your options, and planning accordingly. I feel lucky that I got to spend a week with Udi and absorb some of this. I highly recommend that you attend his class if your doing or thinking of doing distributed systems.&lt;/p&gt; &lt;p&gt;In the coming months, I plan to start working on some SOA projects at &lt;a href="http://wwww.topazti.com"&gt;TOPAZ&lt;/a&gt; and applying what I have learned. I hope to be able to blog about my experience and that Udi will correct me when I say something incorrect. ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5624" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=XyqMJPc8"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/kKIP9lzmVBY" height="1" width="1"/&gt;</description><category domain="http://www.lostechies.com/blogs/rhouston/archive/tags/SOA/default.aspx">SOA</category><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/10/26/udi-s-soa-class-made-me-smart.aspx</feedburner:origLink></item><item><title>Senior Developer Opportunity in Austin</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/DjHrK8XyFB8/senior-developer-opportunity-in-austin.aspx</link><pubDate>Sat, 25 Oct 2008 13:26:40 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:5576</guid><dc:creator>Ray Houston</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=5576</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/10/25/senior-developer-opportunity-in-austin.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.topazti.com/"&gt;TOPAZ Technologies&lt;/a&gt; is currently looking for a &lt;a href="http://www.topazti.com/company/jobs.htm"&gt;Senior Developer&lt;/a&gt; who loves to write .NET code. We&amp;#39;re a product company that builds software solutions for the medical research industry. Here are some of the details for the position:&lt;/p&gt; &lt;p&gt;If you are pragmatic and passionate about software development and enjoy delivering real value to customers, then we may be a good match for you. We are currently looking for a full‐time Senior Developer who does A+ work and who can contribute to the continued success of our team. We are looking for someone with humility who is enthusiastic about sharing knowledge and who believes in continuous improvement. If this describes you and you are interested in working for an exciting company focused on building quality software, we would love to hear from you. Contact us at &lt;a href="mailto:humanresources@topazti.com"&gt;humanresources@topazti.com&lt;/a&gt;.&lt;/p&gt; &lt;h4&gt;Requirements&lt;/h4&gt; &lt;ul&gt; &lt;li&gt;Strong development experience with OO languages  &lt;li&gt;Broad knowledge of .NET and C#  &lt;li&gt;Strong knowledge of building applications for the web  &lt;li&gt;Strong knowledge of design patterns, DDD, refactoring, and TDD  &lt;li&gt;Experience with Agile methodologies such as SCRUM and XP  &lt;li&gt;Experience with ORMs such as NHibernate  &lt;li&gt;Experience as a leader and mentor  &lt;li&gt;Silverlight knowledge a plus  &lt;li&gt;Windows Mobile knowledge a plus &lt;/li&gt;&lt;/ul&gt; &lt;h4&gt;Responsibilities&lt;/h4&gt; &lt;ul&gt; &lt;li&gt;Report to the Director of Development  &lt;li&gt;Provide technical analysis and designs for features  &lt;li&gt;Incrementally estimate and implement features from feature backlog using TDD/BDD  &lt;li&gt;Identify and mitigate risks  &lt;li&gt;Mentor other team members and lead by example  &lt;li&gt;Bring new ideas to the team  &lt;li&gt;Keep up to date on the latest technologies &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;TOPAZ Technologies is an established leader in the development and support of software solutions for medical research. We have solid foundation of clients including leaders in the pharmaceutical, biotech, university, government, and private research organizations.&amp;nbsp; We are privately owned and offers excellent benefits to employees. TOPAZ is also a supporter of the development community.  &lt;p&gt;I should probably add that this is not a work from home position.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5576" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=Gh7Muv4V"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/DjHrK8XyFB8" height="1" width="1"/&gt;</description><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/10/25/senior-developer-opportunity-in-austin.aspx</feedburner:origLink></item><item><title>Single-Responsibility Versus Needless Complexity</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/PjqFSSpjz8E/single-responsibility-versus-needless-complexity.aspx</link><pubDate>Sun, 05 Oct 2008 22:07:10 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:5263</guid><dc:creator>Ray Houston</dc:creator><slash:comments>10</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=5263</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/10/05/single-responsibility-versus-needless-complexity.aspx#comments</comments><description>&lt;p&gt;At &lt;a href="http://www.lostechies.com/blogs/chad_myers/archive/2008/09/15/announcing-pablo-s-days-of-tdd-in-austin-tx.aspx"&gt;Pablo&amp;#39;s Day of TDD&lt;/a&gt;, we were discussing the &lt;a href="http://www.lostechies.com/blogs/sean_chambers/archive/2008/03/15/ptom-single-responsibility-principle.aspx"&gt;Single-Responsibility Principle (SRP)&lt;/a&gt; while working through one of the labs and a question came up about a piece of code. The code in question looked something like the following (warning: this is over simplified code to show a point):&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; Login(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; username, &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; password)
{
    var user = userRepo.GetUserByUsername(username);

    &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt;(user == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)
        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;;

    &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (loginValidator.IsValid(user, password))
        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;

    user.FailedLoginAttempts++;

    &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (user.FailedLoginAttempts &amp;gt;= 3)
        user.LockedOut = &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;

    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;;
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This was from the a LoginService class and this was its only method. The question was whether or not this violates SRP because it&amp;#39;s in charge of incrementing FailLoginAttempts as well as locking the user out after 3 failed attempts. I believe we answered the question with a &amp;quot;depends&amp;quot;, but it bothered me that we didn&amp;#39;t have a better answer. Personally, I wouldn&amp;#39;t have busted this up into another class, but I didn&amp;#39;t have a good argument to stand on.&lt;/p&gt;
&lt;p&gt;Today I went searching through &lt;a href="http://www.amazon.com/Principles-Patterns-Practices-Robert-Martin/dp/0131857258"&gt;Agile Principle, Patterns, and Practices in C#&lt;/a&gt; looking for a better answer. In the chapter on SRP, the book gives an example of an interface of a modem that can Dial/Hang-up and Send/Receive. The former is connection management and the later is data communication. The book asks the question as to whether or not these responsibilities should be separated. The answer is&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&amp;quot;That depends on how the application is changing.&amp;quot;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;It then gives an example to how a change might violate SRP, but then states:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&amp;quot;If, on the other hand,&amp;nbsp; the application is not changing in ways that cause the two responsibilities to change at different times, there is no need to separate them. Indeed, separating them would smell of needless complexity.&amp;quot;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Ah, there&amp;#39;s the backup wisdom that I needed to validate my gut feeling. Here&amp;#39;s one final quote from the book:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&amp;quot;There is a corollary here. An axis of change is an axis of change only if the changes occur. It is not wise to apply SRP (or any other principle, for that matter) if there is no symptom.&amp;quot;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I think applying SRP is about applying good judgement. You certainly don&amp;#39;t want to wait until you have to make a change before you think about SRP, but you don&amp;#39;t want to over do it either and end up with classes with one method with each having only a couple lines of code.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d1e871ed-36c4-492e-a7d0-8c8a93a80692" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Principles" rel="tag"&gt;Principles&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5263" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=5yQLQEgP"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/PjqFSSpjz8E" height="1" width="1"/&gt;</description><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/10/05/single-responsibility-versus-needless-complexity.aspx</feedburner:origLink></item><item><title>Learning TDD</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/fwjBqf4E0Ko/learning-tdd.aspx</link><pubDate>Wed, 24 Sep 2008 01:22:19 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:5136</guid><dc:creator>Ray Houston</dc:creator><slash:comments>9</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=5136</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/09/23/learning-tdd.aspx#comments</comments><description>&lt;p&gt;Learning TDD takes time and can be especially tough if you don&amp;#39;t have an opportunity to work with folks that are already doing TDD. It requires you to think and work differently and there are many pitfalls along the way. I know that I&amp;#39;ve made a ton of mistakes.&lt;/p&gt; &lt;p&gt;When I started working with automated testing, I was writing tests that hit the database. They were big, slow and complex and required a lot of maintenance to keep the data population scripts in check. The tests were very fragile and it seemed like it was almost a full time job to keep them going. At the time, I thought that doing TDD was just about writing your tests first so I tried doing it, but it was just too hard because I wasn&amp;#39;t writing my code in a manner that could be tested easily.&lt;/p&gt; &lt;p&gt;Next I learned about dependency injection and IoC containers which allowed me to decouple my classes and test them in isolation. I learned how to create a mock instance of an interface and pass it into the classes that I was testing to see if they interacted with it properly. This was a million times better than the tests that ran against the database, but I still wasn&amp;#39;t doing it right. I wrote all my tests as interaction tests (versus state base tests) and I ended up with a big mess of fragile unreadable tests that gave me very little feed back to the source of problems when they occurred. Refactoring was painful because I&amp;#39;d have to go fix a ton of tests that I could no longer understand what they were trying to test in the first place.&lt;/p&gt; &lt;p&gt;There are a lot of other mistakes that I&amp;#39;m forgetting right now (or just too embarrassed to mention) and I&amp;#39;m sure there are tons of other people who have made the same ones. As &lt;a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/09/21/ten-tips-to-maximize-the-return-on-your-tdd-investment.aspx"&gt;Jimmy pointed out&lt;/a&gt;, hiring a good coach can be well worth it in avoiding some of the mistakes like I made.&lt;/p&gt; &lt;p&gt;If you&amp;#39;re interested in talking with other folks about TDD, &lt;a href="http://www.lostechies.com/"&gt;Los Techies&lt;/a&gt; is hosting a free event in Austin, TX called &amp;quot;Pablo&amp;#39;s Days of TDD&amp;quot; (PDoTDD). It will be held on Friday October 3rd, 2008 from 2PM-5PM and Saturday, October 4th, 2008 from 9AM to 5PM. This event is for all levels from beginners to masters and will include workshops, discussion, practice, and training around automated unit testing, specifically the practice of TDD. For more information, please see Chad&amp;#39;s post &lt;a href="http://www.lostechies.com/blogs/chad_myers/archive/2008/09/15/announcing-pablo-s-days-of-tdd-in-austin-tx.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:92cbaa4f-c193-4dcc-8526-56e76934a732" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/TDD" rel="tag"&gt;TDD&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5136" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=7fqSem89"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/fwjBqf4E0Ko" height="1" width="1"/&gt;</description><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/09/23/learning-tdd.aspx</feedburner:origLink></item><item><title>How Mr. Buford got me started in software development</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/vv_PEToQO4I/how-mr-buford-got-me-started-in-software-development.aspx</link><pubDate>Sun, 21 Sep 2008 00:50:26 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:5087</guid><dc:creator>Ray Houston</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=5087</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/09/20/how-mr-buford-got-me-started-in-software-development.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.lostechies.com/blogs/jason_meridth/"&gt;Jason&lt;/a&gt; tagged me awhile back for a &lt;a href="http://www.lostechies.com/blogs/jason_meridth/archive/2008/06/27/how-did-i-get-started-in-software-development.aspx"&gt;&amp;quot;How did I get started in software development?&amp;quot;&lt;/a&gt; post and I&amp;#39;m just now getting around to it, but I&amp;#39;m going to change the format a little.&lt;/p&gt; &lt;p&gt;One morning back in 1982/83 when I was in the 6th grade, I was hanging out in the side of the school building trying to look cool (but not) when my science teacher, Mr. Buford, came up and saw me standing there picking my nose and said &amp;quot;Hey kid, you want to learn something?&amp;quot; Mr. Buford was a real big guy and was a bit intimidating. He was one of those teachers we didn&amp;#39;t play around with. I said meekly &amp;quot;ok&amp;quot; and he told me to come with him. He took me into his classroom where he had a TI 99-4A which he used to record our grades. I remember him placing a cartridge in the machine and telling me that it was a program that teaches you the BASIC programming language and that I was to sit there and go through the tutorial. Of course I was extremely excited to be playing with the computer since I had never messed with one before. The tutorial was interactive and you could write code as you followed along with lessons. I can&amp;#39;t remember exactly how long the tutorial was, but it took me several mornings to go through the whole thing. Then after completing it, I started writing my own programs. Each morning, I would wait for Mr. Buford to get to school so I could play with his computer. I was fascinated by being able to make images and sounds with the machine so I wrote a lot of little programs around those topics. I showed the programs I wrote to Mr. Buford and I clearly remember him being amazed that I could make the computer do those things (I don&amp;#39;t think Mr. Buford ever did the tutorial himself). It was a lot of fun.&lt;/p&gt; &lt;p&gt;When school let out for the summer, I was forced to take a break from the computer. In the late summer of 1983, hurricane Alicia came and tore a lot of things up. I worked cutting and splitting wood of fallen trees and saved enough money to buy my own first computer which was a Commodore VIC-20. This was the first of the many I was to own over the years.&lt;/p&gt; &lt;p&gt;So that&amp;#39;s it. If it hadn&amp;#39;t been for Mr. Buford, I wouldn&amp;#39;t have learned BASIC when I did (or maybe never) and I wouldn&amp;#39;t have spent my hard earned money on my first computer. Instead I probably would have bought a bag of Super Bubble and a fishing reel or some firecrackers or something. It&amp;#39;s amazing how a little encouragement from my 6th grade science teacher helped me get into something which I would end up doing professionally. It&amp;#39;s amazing how such a small thing can be so powerful. Keep that in mind when you have the opportunity to mentor someone. The old saying is true; a little bit goes a long way.&lt;/p&gt; &lt;p&gt;Thanks Mr. Buford.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:87d9bbb1-b36f-4989-a6a2-e5a3ac932dbc" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Mentoring" rel="tag"&gt;Mentoring&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5087" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=Wmboyfed"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/vv_PEToQO4I" height="1" width="1"/&gt;</description><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/09/20/how-mr-buford-got-me-started-in-software-development.aspx</feedburner:origLink></item><item><title>Creating a Silverlight Layout Panel</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/95MYj7HIhgk/creating-a-silverlight-layout-panel.aspx</link><pubDate>Sun, 14 Sep 2008 16:21:04 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:4950</guid><dc:creator>Ray Houston</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=4950</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/09/14/creating-a-silverlight-layout-panel.aspx#comments</comments><description>&lt;p&gt;On our current project, we came across the need to build some custom layout panels in Silverlight to achieve some complex fluid layouts that we could not get from the built in controls. I was amazed to see how easy it was to create your own. This panel that I&amp;#39;m going to show is nothing fancy, but it shows how simple it really is. It will layout it&amp;#39;s children in a diagonal direction from upper left to lower right.&lt;/p&gt; &lt;p&gt;The first thing we need to do is create a new class and inherit from Panel. Panel is the base class for the built-in layout controls such as Grid and StackPanel.&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;public class DiagonalStackPanel : Panel
{
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The next thing is to override the MeasureOverride() method. In this method you should iterate through the Children collection and call the Measure() method on each child. After Measure() is called, the DesiredSize property of the child will be populated with the size in which the child wants to be rendered.&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;protected override Size MeasureOverride(Size availableSize)
{
    double totalWidth = 0;
    double totalHeight = 0;

    foreach (var child in Children)
    {
        child.Measure(availableSize);

        totalWidth += child.DesiredSize.Width;
        totalHeight += child.DesiredSize.Height;
    }

    return new Size(totalWidth, totalHeight);
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can see that we&amp;#39;re adding up all the widths and heights of each child and returning the size (desired) for our Panel.&lt;/p&gt;
&lt;p&gt;Next we override the ArrangeOverride() method. This is where we actually layout the children in the diagonal pattern. We do that by calculating the running total sizes of the child controls and calling Arrange() on each child with the appropriate sizing Rect object.&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;protected override Size ArrangeOverride(Size finalSize)
{
    double runningWidth = 0;
    double runningHeight = 0;

    foreach (var child in Children)
    {
        var width = child.DesiredSize.Width;
        var height = child.DesiredSize.Width;

        var finalRect = new Rect(runningWidth, runningHeight, width, height);
        child.Arrange(finalRect);

        runningWidth += width;
        runningHeight += height;
    }

    return new Size(runningWidth, runningHeight);
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now we can use our panel like so:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;UserControl&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;x:Class&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;LayoutPanelExample.Page&amp;quot;&lt;/span&gt;
    &lt;span style="color:#ff0000;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt; 
    &lt;span style="color:#ff0000;"&gt;xmlns:x&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt; 
    &lt;span style="color:#ff0000;"&gt;xmlns:c&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;clr-namespace:LayoutPanelExample&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Grid&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;x:Name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Background&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;White&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;c:DiagonalStackPanel&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Button&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Content&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Button&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Button&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Content&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Button&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Button&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Content&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Button&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Button&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Content&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Button&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Button&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Content&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Button&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Button&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Content&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Button&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;c:DiagonalStackPanel&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;Grid&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;UserControl&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and we&amp;#39;ll get something that looks like:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.lostechies.com/blogs/rhouston/WindowsLiveWriter/CreatingaSilverlightLayoutPanel_A7C9/image_2.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="226" alt="image" src="http://www.lostechies.com/blogs/rhouston/WindowsLiveWriter/CreatingaSilverlightLayoutPanel_A7C9/image_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;You could extend this by added Dependency Properties to the panel so that you can customize how each child reacts in the layout. This is how the Grid works. It looks at the properties set on the child elements and figures out what row and column to place them in.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:de428cf4-04e1-4b96-95f0-a4430343c2d7" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Silverlight" rel="tag"&gt;Silverlight&lt;/a&gt;,&lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=4950" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=4QEKj7WA"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/95MYj7HIhgk" height="1" width="1"/&gt;</description><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/09/14/creating-a-silverlight-layout-panel.aspx</feedburner:origLink></item><item><title>From Flex to Silverlight</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/uve17vCegMI/from-flex-to-silverlight.aspx</link><pubDate>Sat, 13 Sep 2008 14:52:06 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:4937</guid><dc:creator>Ray Houston</dc:creator><slash:comments>22</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=4937</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/09/13/from-flex-to-silverlight.aspx#comments</comments><description>&lt;p&gt;A couple of years ago my company started development on a web product that had designs for a very rich user interface. We started out building a AJAX HTML based application and realized very soon that we were having to work really hard to make HTML and CSS do what we wanted it to do and in many cases it just wasn&amp;#39;t happening.&lt;/p&gt; &lt;p&gt;Our UI designer was doing prototypes in &lt;a href="http://www.adobe.com/products/flex/"&gt;Flex&lt;/a&gt; (which I didn&amp;#39;t know what it was at the time) but his stuff was really cool and we starting talking about it. I was skeptical about Flex at first, but it turned out to be a real platform for developing rich Internet applications. Anyway, to make a very long story short, we chose Flex as the front end of our .NET web application.&lt;/p&gt; &lt;p&gt;In the beginning Flex was cool. It gave us a strongly typed object oriented language (ActionScript 3) and IDE support in Eclipse. We were able to develop some really slick things in a fraction of the effort if we would have done them using DHTML/CSS. It was good, but working in Flex did have its negatives as well. Some of the things that we struggled with were&lt;/p&gt; &lt;ul&gt; &lt;li&gt;We&amp;#39;re .NET folks, so there was a learning curve  &lt;li&gt;Extra time in working with two IDE&amp;#39;s to develop in (Eclipse and Visual Studio for Flex and .NET respectfully)  &lt;li&gt;The IDE plug-in was very buggy  &lt;li&gt;No refactoring support  &lt;li&gt;No real testing support  &lt;li&gt;Compiles painfully slow on large projects  &lt;li&gt;Not a lot of support from Adobe when we would have problems&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;I had been keeping my eye on &lt;a href="http://silverlight.net/"&gt;Silverlight&lt;/a&gt; waiting to see how it was all going to play out. When the first beta of 2.0 came out, we started looking at it hard. Then in April at &lt;a href="http://altdotnet.org/"&gt;ALT.NET&lt;/a&gt; Seattle, I had the opportunity to steal a few moments of &lt;a href="http://weblogs.asp.net/scottgu/"&gt;Scott Guthrie&amp;#39;s&lt;/a&gt; time and ask him about what to expect from Silverlight in the future. The guy&amp;#39;s enthusiasm about what they were doing completely sold me. We started our Silverlight project that following week and haven&amp;#39;t looked back.&lt;/p&gt; &lt;p&gt;I&amp;#39;m truly digging Silverlight. It is amazing to be able to write .NET code that runs in the browsers. I even forget that I&amp;#39;m working in a browser sometimes. There are a few things we miss from Flex, but nothing we couldn&amp;#39;t create ourselves without too much effort. Some of the things we now get to take advantage of are&lt;/p&gt; &lt;ul&gt; &lt;li&gt;All the C# language features  &lt;li&gt;Passing .NET types to and from the server  &lt;li&gt;Reflection  &lt;li&gt;Testing Tools  &lt;li&gt;We able to use &lt;a href="http://www.jetbrains.com/resharper/"&gt;Resharper&lt;/a&gt; (can I get a &amp;quot;heck yeah&amp;quot; for this one?)  &lt;li&gt;Support of Microsoft&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;That last point is really important. Microsoft made us part of their early adopters program and we so have good channels of communication with the team. We tried to do something like that with Adobe, but I guess we never talked to the right person.&lt;/p&gt; &lt;p&gt;I think the Silverlight team has done a great job and I&amp;#39;m looking forward to the future releases.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:0f5a42b6-9d4a-47a4-aa2f-d4557951ae16" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Silverlight" rel="tag"&gt;Silverlight&lt;/a&gt;,&lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Flex" rel="tag"&gt;Flex&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=4937" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=LqdaLL8M"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/uve17vCegMI" height="1" width="1"/&gt;</description><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/09/13/from-flex-to-silverlight.aspx</feedburner:origLink></item><item><title>Do Anonymous Methods Prevent Declaring Types from Being GC'd?</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/iyL2c9PpgFU/do-anonymous-methods-prevent-declaring-types-from-being-gc-d.aspx</link><pubDate>Thu, 22 May 2008 01:57:02 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:3355</guid><dc:creator>Ray Houston</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=3355</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/05/21/do-anonymous-methods-prevent-declaring-types-from-being-gc-d.aspx#comments</comments><description>&lt;p&gt;It seems that they do if they reference members of the declaring type. This makes perfect sense now that I think about it, but I didn&amp;#39;t think about it earlier and wrote some code that caused a memory leak. I had an object acting as a singleton and referencing a delegate instance that was created from an object acting as a non singleton. Bam! Memory Leak.&lt;/p&gt; &lt;p&gt;I setup a little test to demonstrate. Here is a class that has two methods which return delegate instances:&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; TestSource
{
    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; internalValue = &lt;span style="color:#006080;"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;;

    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; Func&amp;lt;&lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt;&amp;gt; GetFunc1()
    {
        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; () =&amp;gt; 1 == 1;
    }

    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; Func&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&amp;gt; GetFunc2()
    {
        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; () =&amp;gt; internalValue;
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Notice that GetFunc1() doesn&amp;#39;t have any references to internal members, but GetFunc2() does. Here&amp;#39;s the test class:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Program
{
    &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;[] args)
    {
        &lt;span style="color:#008000;"&gt;// hold no references to TestSource&lt;/span&gt;
        TestFuncInstance(&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; TestSource().GetFunc1());
        TestFuncInstance(&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; TestSource().GetFunc2());

        Console.WriteLine(&lt;span style="color:#006080;"&gt;&amp;quot;Press Enter to continue.&amp;quot;&lt;/span&gt;);
        Console.ReadLine();
    }

    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; TestFuncInstance(Delegate func)
    {
        Thread.Sleep(1000);&lt;span style="color:#008000;"&gt;// give some time for GC&lt;/span&gt;

        Console.WriteLine(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#006080;"&gt;&amp;quot;Method: {0}&amp;quot;&lt;/span&gt;,func.Method));
        Console.WriteLine(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#006080;"&gt;&amp;quot;DeclaringType: {0}&amp;quot;&lt;/span&gt;, func.Method.DeclaringType));
        Console.WriteLine(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#006080;"&gt;&amp;quot;Target: {0}&amp;quot;&lt;/span&gt;, func.Target ?? &lt;span style="color:#006080;"&gt;&amp;quot;null&amp;quot;&lt;/span&gt;));

        Console.WriteLine();
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This creates two separate instances of TestSource and passes the result of the two GetFunc methods to a test method. Notice that there are no declared variable references to the TestSource object. Here&amp;#39;s the output of the test:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;Method: Boolean &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;GetFunc1&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;b__0()
DeclaringType: TestingDelegates.TestSource
Target: null 

Method: System.String &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;GetFunc2&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;b__2()
DeclaringType: TestingDelegates.TestSource
Target: TestingDelegates.TestSource 

Press Enter to continue.
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I know this test isn&amp;#39;t very scientific, but you&amp;#39;ll see that Func1&amp;#39;s target is null while Func2&amp;#39;s target is not. Func2 has to hold a reference to the declaring object so that it can do it&amp;#39;s job when invoked. Func1 does not need a reference, and seems to free up the declaring object to be garbage collected. This is definitely something to keep in mind when passing around delegates.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:613036e7-925a-4963-b7c5-a643b9992875" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;,&lt;a href="http://technorati.com/tags/delegates" rel="tag"&gt;delegates&lt;/a&gt;,&lt;a href="http://technorati.com/tags/GC" rel="tag"&gt;GC&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=3355" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=WvZS6G1h"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/iyL2c9PpgFU" height="1" width="1"/&gt;</description><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/05/21/do-anonymous-methods-prevent-declaring-types-from-being-gc-d.aspx</feedburner:origLink></item><item><title>Synchronizing UI Operations with Asynchronous Dependencies</title><link>http://feedproxy.google.com/~r/RayHoustonBlog/~3/13UvTV-_Spg/synchronizing-ui-operations-with-asynchronous-dependencies.aspx</link><pubDate>Thu, 15 May 2008 02:14:21 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:3244</guid><dc:creator>Ray Houston</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/rhouston/rsscomments.aspx?PostID=3244</wfw:commentRss><comments>http://www.lostechies.com/blogs/rhouston/archive/2008/05/14/synchronizing-ui-operations-with-asynchronous-dependencies.aspx#comments</comments><description>&lt;p&gt;When working with asynchronous data access such as using a Silverlight client to access data from a server side service, you will inevitably run into the situation where you have two or more calls which have results that need to be processed in a synchronous manner. A simple example is populating a list box from server side data and then making a second call to get the value that needs to be selected. You could wait until the list is populated before making the second call, but that would be a waste.&lt;/p&gt; &lt;p&gt;I built a little helper object that allows you to define Action delegates that will get executed in a specific order once all pending operations have completed. Below is a snippet of how it can be used.&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; ILoginService loginService;
&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; ILoginView loginView;
&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; OperationSync localeOpSync = 
        &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; OperationSync(LocaleOps.GetLocales, LocaleOps.GetDefaultLocale);

&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; PopulateLocales()
{
    loginService.GetLocales(HandleGetLocalesResult);
    loginService.GetDefaultLocale(HandleGetDefaultLocaleResult);
}

&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; HandleGetDefaultLocaleResult(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; result)
{
    localeOpSync.OpCompleted(LocaleOps.GetDefaultLocale, GetSetSelectedLocaleAction(result));
}

&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; HandleGetLocalesResult(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;[] result)
{
    localeOpSync.OpCompleted(LocaleOps.GetLocales, GetSetLocaleSelectionAction(result));
}

&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; Action GetSetSelectedLocaleAction(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; result)
{
    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; () =&amp;gt; loginView.SetSelectedLocale(result);
}

&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; Action GetSetLocaleSelectionAction(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;[] result)
{
    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; ()=&amp;gt; loginView.SetLocaleSelections(result);
}&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;In this example, there are two asynchronous service methods which get called. Their results are passed to handler methods where they are processed by Actions, but those Actions don&amp;#39;t execute until both OpComplete methods have fired (actually the last OpComplete triggers the execution of all the Actions. It doesn&amp;#39;t matter which call returns first. Their associated Actions will execute in the order defined by the keys in the creation of the OperationSync object. There are a million different ways to put this together with lambdas and anonymous methods, but I tried to bust it up here so it would be easier to follow.&lt;/div&gt;
&lt;p&gt;To show how it works I&amp;#39;ve included a subset of the unit tests (with extension methods and other goodies stripped out). The setup for all the specs is at the bottom of the code snippet.&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;[TestFixture]
&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; when_not_completing_all_ops 
    : behaves_like_setting_up_operation_actions
{
    [Test]
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; should_not_execute_actions()
    {
        OpSync.OpCompleted(OpKey.One, Action1);
        OpSync.OpCompleted(OpKey.Two, Action2);

        CollectionAssert.IsEmpty(ActionResults);
    }
}

[TestFixture]
&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; when_completing_all_ops_in_key_order 
    : behaves_like_setting_up_operation_actions
{
    [Test]
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; should_execute_actions_in_key_order()
    {
        OpSync.OpCompleted(OpKey.One, Action1);
        OpSync.OpCompleted(OpKey.Two, Action2);
        OpSync.OpCompleted(OpKey.Three, Action3);

        Assert_That_ActionResults_Fire_In_Correct_Order();
    }
}

[TestFixture]
&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; when_completing_all_ops_not_in_key_order 
    : behaves_like_setting_up_operation_actions
{
    [Test]
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; should_execute_actions_in_key_order()
    {
        OpSync.OpCompleted(OpKey.Two, Action2);
        OpSync.OpCompleted(OpKey.Three, Action3);
        OpSync.OpCompleted(OpKey.One, Action1);

        Assert_That_ActionResults_Fire_In_Correct_Order();
    }
}

&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;abstract&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; behaves_like_setting_up_operation_actions
{
    &lt;span style="color:#0000ff;"&gt;protected&lt;/span&gt; OperationSync OpSync { get; set; }
    &lt;span style="color:#0000ff;"&gt;protected&lt;/span&gt; Action Action1 { get; set; }
    &lt;span style="color:#0000ff;"&gt;protected&lt;/span&gt; Action Action2 { get; set; }
    &lt;span style="color:#0000ff;"&gt;protected&lt;/span&gt; Action Action3 { get; set; }
    &lt;span style="color:#0000ff;"&gt;protected&lt;/span&gt; List&amp;lt;OpKey&amp;gt; ActionResults { get; set; }

    [SetUp]
    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Before_Each_Spec()
    {
        OpSync = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; OperationSync(OpKey.One, OpKey.Two, OpKey.Three);

        Action1 = () =&amp;gt; ActionResults.Add(OpKey.One);
        Action2 = () =&amp;gt; ActionResults.Add(OpKey.Two);
        Action3 = () =&amp;gt; ActionResults.Add(OpKey.Three);

        ActionResults = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; List&amp;lt;OpKey&amp;gt;();
    }

    &lt;span style="color:#0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Assert_That_ActionResults_Fire_In_Correct_Order()
    {
        Assert.That(ActionResults.Count, Is.EqualTo(3));
        Assert.That(ActionResults[0], Is.EqualTo(OpKey.One));
        Assert.That(ActionResults[1], Is.EqualTo(OpKey.Two));
        Assert.That(ActionResults[2], Is.EqualTo(OpKey.Three));
    }

    &lt;span style="color:#0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;enum&lt;/span&gt; OpKey
    {
        One,
        Two,
        Three
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The keys can be anything. I have just been creating a private enum in the class where I need them. Here&amp;#39;s the OperationSync class that handles it all:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; OperationSync
{
    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; syncRoot = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;object&lt;/span&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;object&lt;/span&gt;[] keys;
    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt;&amp;gt; keyKeepActionAfterExecute = 
        &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt;&amp;gt;();

    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt;, Action&amp;gt; keyActions = 
        &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt;, Action&amp;gt;();

    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; OperationSync(&lt;span style="color:#0000ff;"&gt;params&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;object&lt;/span&gt;[] operationKeys)
    {
        keys = operationKeys;

        &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; (var o &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; operationKeys)
        {
            keyActions.Add(o, &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;);
        }
    }

    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; OpCompleted(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; key, Action action)
    {
        OpCompleted(key, action, &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;);
    }

    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; OpCompleted(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; key, Action action, &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; keepActionAfterExecute)
    {
        &lt;span style="color:#0000ff;"&gt;lock&lt;/span&gt; (syncRoot)
        {
            &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (!keyActions.ContainsKey(key))
                &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; UIException(&lt;span style="color:#006080;"&gt;&amp;quot;Key &amp;#39;{0}&amp;#39; not found.&amp;quot;&lt;/span&gt;);

            keyActions[key] = action;
            keyKeepActionAfterExecute[key] = keepActionAfterExecute;

            &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (AllOpsComplete())
                ProcessActions();
        }
    }

    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; ProcessActions()
    {
        ExecuteEachAction();

        ClearActionsIfIndicated();
    }

    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; ExecuteEachAction()
    {
        &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; (var key &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; keys)
        {
            keyActions[key]();
        }
    }

    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; ClearActionsIfIndicated()
    {
        &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; (var key &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; keys)
        {
            &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (!keyKeepActionAfterExecute[key])
                keyActions[key] = &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;;
        }
    }

    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; AllOpsComplete()
    {
        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; keyActions.All(pair =&amp;gt; pair.Value != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;);
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There&amp;#39;s probably a fancy smancy AJAX pattern name for this sort of thing. Let me know if you come across one.&lt;/p&gt;
&lt;p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:2d6d99b3-baf1-4fda-9fab-31dd9410c69b" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/C#" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Silverlight" rel="tag"&gt;Silverlight&lt;/a&gt;,&lt;a href="http://technorati.com/tags/AJAX" rel="tag"&gt;AJAX&lt;/a&gt;,&lt;a href="http://technorati.com/tags/UI" rel="tag"&gt;UI&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=3244" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/RayHoustonBlog?a=E7op4gRs"&gt;&lt;img src="http://feeds.feedburner.com/~f/RayHoustonBlog?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RayHoustonBlog/~4/13UvTV-_Spg" height="1" width="1"/&gt;</description><feedburner:origLink>http://www.lostechies.com/blogs/rhouston/archive/2008/05/14/synchronizing-ui-operations-with-asynchronous-dependencies.aspx</feedburner:origLink></item></channel></rss>
