<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.lostechies.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Colin Ramsay</title><subtitle type="html" /><id>http://www.lostechies.com/blogs/colin_ramsay/atom.aspx</id><link rel="alternate" type="text/html" href="http://www.lostechies.com/blogs/colin_ramsay/default.aspx" /><link rel="self" type="application/atom+xml" href="http://www.lostechies.com/blogs/colin_ramsay/atom.aspx" /><generator uri="http://communityserver.org" version="4.1.30929.2835">Community Server</generator><updated>2007-10-01T23:15:00Z</updated><entry><title>PTOM: Breaking Free from HttpContext</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2009/05/05/breaking-free-from-httpcontext.aspx" /><id>/blogs/colin_ramsay/archive/2009/05/05/breaking-free-from-httpcontext.aspx</id><published>2009-05-05T03:08:00Z</published><updated>2009-05-05T03:08:00Z</updated><content type="html">&lt;p&gt;The System.Web.HttpContext class is a real heavyweight of the .NET Framework. It holds a wealth of information on the current server context, from the details of the current user request to a host of details about the server. It&amp;#39;s accessible from the HttpContext.Current static property, which means you can get hold of this information at and point in your code. Whether this is a strength or a weakness depends on your point of view, but consider the following code:&lt;/p&gt;
&lt;pre class="code"&gt;public class AuthenticationService&lt;br /&gt;{&lt;br /&gt;    public IRepository Repository { get; set; }&lt;br /&gt;&lt;br /&gt;    public void Login(string username, string password)&lt;br /&gt;    {&lt;br /&gt;        User user = Repository.FindByLogin(username, password);&lt;br /&gt;&lt;br /&gt;        HttpContext.Current.Session[&amp;quot;currentuserid&amp;quot;] = user.Id;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;
This type of code is probably pretty widespread; separate authentication code into a separate class. The problem with this type of code comes when you want to test it. Consider this test snippet:
&lt;/p&gt;
&lt;pre&gt;[TestMethod]&lt;br /&gt;public void Should_Retrieve_User_From_Repo()&lt;br /&gt;{&lt;br /&gt;    _authService.Login(username, password);&lt;br /&gt;    _repo.AssertWasCalled(x =&amp;gt; x.FindByLogin(username, password);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;
This will fail hard, because when your test runs, you don&amp;#39;t have a current HttpContext available to work with. In theory, you could fire up a webserver class and populate HttpContext.Current and everything would work just fine; with early versions of the Castle Monorail project, the Controller test support did something similar. However, this is pretty unwieldy and not to mention slow.
Of course we do have some horrible situations in which teams don&amp;#39;t run these kind of tests, so they&amp;#39;re probably thinking that they don&amp;#39;t care. They always run their code with a valid HttpContext available and are perfectly happy. Wait till you try and reuse your code to integrate with a third party which calls your authentication service. Ouch.
So the bottom line is that we need to make sure HttpContext.Current is kept as far away from our code as possible. Another example of HttpContext usage is something like this:
&lt;/p&gt;
&lt;pre&gt;public void Log(string message)&lt;br /&gt;{&lt;br /&gt;    WriteFile(message, DateTime.Now, HttpContext.Current.Url);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;
So we&amp;#39;re writing a log message along with the time and the page where the message was logged. We need this information for debugging, so it&amp;#39;s understandable why this code arises, but again we can see testing issues with HttpContext. Fortunately in this case it&amp;#39;s easy to fix:&lt;/p&gt;
&lt;pre&gt;public void Log(string message, string url)&lt;br /&gt;{&lt;br /&gt;    WriteFile(message, DateTime.Now, url);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Of course this kind of solution applies to any static class you need to pull out, so let&amp;#39;s look at an example which is more closely related to HttpContext: cookies. A standard approach would see us doing something like this:&lt;/p&gt;
&lt;pre&gt;private void PersistUser(string encryptedUserIdentifier)&lt;br /&gt;{&lt;br /&gt;    HttpCookie cookie = new HttpCookie(&amp;quot;user&amp;quot;);&lt;br /&gt;    cookie.Value = encryptedUserIdentifier;&lt;br /&gt;    cookie.Expiry = DateTime.Now.AddDays(14);&lt;br /&gt;    Response.Cookies.Add(cookie);&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;
This does the job, and adds a cookie to the response so that the browser will acknowledge it. The problem again lies in testing this code; without an HttpContext, we&amp;#39;re in trouble. Because a lot of new C# code is working with ASP.NET MVC and test-first practices, we need to take that in to account in every part of our application. How about this instead:
&lt;/p&gt;
&lt;pre&gt;private readonly ICookieContainer _cookies;&lt;br /&gt;&lt;br /&gt;public Controller(ICookieContainer cookieContainer)&lt;br /&gt;{&lt;br /&gt;    _cookies = cookieContainer;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void PersistUser(string encryptedUserIdentifier)&lt;br /&gt;{&lt;br /&gt;    _cookies.Set(&amp;quot;user&amp;quot;, encryptedUserIdentifier, DateTime.Now.AddDays(14));&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;
Now, we don&amp;#39;t include any kind of code which references the cookie implementation directly, and that in turn means we don&amp;#39;t use HttpContext.Current. We provide an implementation of an ICookieContainer via the constructor. That interface and implementation could look like this:
&lt;/p&gt;
&lt;pre&gt;public interface ICookieContainer&lt;br /&gt;{&lt;br /&gt;    void Set(string name, string value, DateTime expires);&lt;br /&gt;    string Get(string name);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class HttpCookieContainer : ICookieContainer&lt;br /&gt;{&lt;br /&gt;    public void Set(string name, string value, DateTime expires)&lt;br /&gt;    {&lt;br /&gt;        HttpCookie cookie = new HttpCookie(&amp;quot;user&amp;quot;);&lt;br /&gt;        cookie.Value = encryptedUserIdentifier;&lt;br /&gt;        cookie.Expiry = DateTime.Now.AddDays(14);&lt;br /&gt;        Response.Cookies.Add(cookie);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;
Now, looking at this you might be wondering what on earth the point is - this is exactly the same code but in a different class! The important thing is that the first set of code is likely to be part of a bigger controller class, a class which you want to keep as thin as possible. So we pull the cookie handling code out and then the controller doesn&amp;#39;t have to be concerned about it at all.
Similar approaches can be used where ever HttpContext touches your code. The important thing is that because HttpContext is such a heavyweight, we can break it apart and use only the parts that are needed by wrapping them up into custom classes which can be injected where they&amp;#39;re needed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=PTOM%3a+Breaking+Free+from+HttpContext&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2009%2f05%2f05%2fbreaking-free-from-httpcontext.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2009%2f05%2f05%2fbreaking-free-from-httpcontext.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=20302" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author></entry><entry><title>Castle MicroKernel Fluent Event Wiring</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2009/01/25/castle-microkernel-fluent-event-wiring.aspx" /><id>/blogs/colin_ramsay/archive/2009/01/25/castle-microkernel-fluent-event-wiring.aspx</id><published>2009-01-25T06:32:00Z</published><updated>2009-01-25T06:32:00Z</updated><content type="html">&lt;p&gt;The Castle MicroKernel Registration API is also used in Windsor, and both have a facility to allow a components to subscribe to events exposed by each other. Right now, the only way to use the fluent API to configure the facility is to go right down and build the configuration nodes (taken from &lt;a href="http://blogger.forgottenskies.com/?p=266"&gt;http://blogger.forgottenskies.com/?p=266&lt;/a&gt;):&lt;/p&gt;
&lt;p&gt;
&lt;textarea name="code" class="c-sharp"&gt;container.Register(Component.For&amp;lt;PublisherClass&amp;gt;()
    .Configuration(Child.ForName(&amp;quot;subscribers&amp;quot;)
        .Eq(
            Child.ForName(&amp;quot;subscriber&amp;quot;).Eq(
                Attrib.ForName(&amp;quot;id&amp;quot;).Eq(&amp;quot;Subscriber&amp;quot;),
                Attrib.ForName(&amp;quot;event&amp;quot;).Eq(&amp;quot;Published&amp;quot;),
                Attrib.ForName(&amp;quot;handler&amp;quot;).Eq(&amp;quot;OnPublish&amp;quot;)
            ),
            Child.ForName(&amp;quot;subscriber&amp;quot;).Eq(
                Attrib.ForName(&amp;quot;id&amp;quot;).Eq(&amp;quot;Subscriber&amp;quot;),
                Attrib.ForName(&amp;quot;event&amp;quot;).Eq(&amp;quot;Published&amp;quot;),
                Attrib.ForName(&amp;quot;handler&amp;quot;).Eq(&amp;quot;OnPublish&amp;quot;)
            ),
        )
    )
);
&lt;/textarea&gt;&lt;/p&gt;
&lt;p&gt;This works fine, but it&amp;#39;s a little verbose for my liking. I&amp;#39;ve managed to get it down to:&lt;/p&gt;
&lt;p&gt;
&lt;textarea name="code" class="c-sharp"&gt;container.Register(Component.For&amp;lt;PublisherClass&amp;gt;()
	.Subscribers(
		Subscriber.ForComponent(&amp;quot;Subscriber&amp;quot;, &amp;quot;Published&amp;quot;, &amp;quot;OnPublish&amp;quot;),
        Subscriber.ForComponent(&amp;quot;Subscriber&amp;quot;, &amp;quot;Published&amp;quot;, &amp;quot;OnPublish&amp;quot;)
    )
);
&lt;/textarea&gt;&lt;/p&gt;
&lt;p&gt;Much nicer! In effect all I&amp;#39;ve done is abstract away the building of the configuration nodes. Firstly I have a Subscriber class:&lt;/p&gt;
&lt;p&gt;
&lt;textarea name="code" class="c-sharp"&gt;public class Subscriber
{
    public class SubscriberInfo
    {
        public string Id { get; set; }
        public string EventName { get; set; }
        public string HandlerMethodName { get; set; }
    }
    public static SubscriberInfo ForComponent(string id, string eventName, string handlerMethodName)
    {
        return new SubscriberInfo{Id = id, EventName = eventName, HandlerMethodName = handlerMethodName};
    }
}
&lt;/textarea&gt;&lt;/p&gt;
&lt;p&gt;Then the actual business end of things is the Extension method which allows me to use this:&lt;/p&gt;
&lt;p&gt;
&lt;textarea name="code" class="c-sharp"&gt;public static class EventWiringFacilityRegistrationExtensions
{
    public static ComponentRegistration&amp;lt;S&amp;gt; Subscribers&amp;lt;S&amp;gt;(this ComponentRegistration&amp;lt;S&amp;gt; componentRegistration, params Subscriber.SubscriberInfo[] subscribers)
    {
        var subscriberNodes =    from s in subscribers select
                                Child.ForName(&amp;quot;subscriber&amp;quot;)
                                .Eq(
                                    Attrib.ForName(&amp;quot;id&amp;quot;).Eq(s.Id),
                                    Attrib.ForName(&amp;quot;event&amp;quot;).Eq(s.EventName),
                                    Attrib.ForName(&amp;quot;handler&amp;quot;).Eq(s.HandlerMethodName)
                                );
        var subs = Child.ForName(&amp;quot;subscribers&amp;quot;).Eq(subscriberNodes.ToArray());
        return componentRegistration.AddDescriptor(new ConfigurationDescriptor&amp;lt;S&amp;gt;(subs));
    }
}
&lt;/textarea&gt;&lt;/p&gt;
&lt;p&gt;As you can see, I&amp;#39;m just pulling out the data from the SubscriberInfo array and building up the configuration nodes. These are then passed to a ConfigurationDescriptor which is where the real business happens. Writing a custom descriptor would probably make for a more elegant solution, so if anyone&amp;#39;s got any suggestions then I&amp;#39;m all ears. When I work out how to write a test for this behaviour I&amp;#39;ll try and sort out a Castle patch.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Castle+MicroKernel+Fluent+Event+Wiring&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2009%2f01%2f25%2fcastle-microkernel-fluent-event-wiring.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2009%2f01%2f25%2fcastle-microkernel-fluent-event-wiring.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=14750" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author><category term="c#" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/c_2300_/default.aspx" /><category term="microkernel" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/microkernel/default.aspx" /><category term="windsor" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/windsor/default.aspx" /></entry><entry><title>The State of Windows Mobile</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2009/01/14/the-state-of-windows-mobile.aspx" /><id>/blogs/colin_ramsay/archive/2009/01/14/the-state-of-windows-mobile.aspx</id><published>2009-01-14T12:57:00Z</published><updated>2009-01-14T12:57:00Z</updated><content type="html">&lt;p&gt;&amp;ldquo;Have you done any Windows Mobile development?&amp;rdquo;&lt;br /&gt;
&amp;ldquo;A tiny bit. Isn&amp;rsquo;t it just like Winforms but on a phone?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;And from such an innocent beginning, a world of pain did explode into my universe. Just like Winforms on a phone is it? What&amp;rsquo;s the difference between the Compact Framework, Smartphone development, Pocket PC development, Windows Mobile? So many terms! So little time!&lt;/p&gt;
&lt;p&gt;Windows Mobile is the operating system, just like Windows Vista. The Compact Framework is just like the .NET Framework on the desktop. As for the difference between a Smartphone and a Pocket PC, well, you&amp;rsquo;ve got me there. I picked Smartphone because my device had phone functionality and it seems to be working so far. There are separate SDKs for each, so I assume there are some key differences which escape me. With Windows Mobile 6, the Smartphone and Pocket PC SDKs are now Windows Mobile 6 Standard and Windows Mobile 6 Professional, respectively. I think.&lt;/p&gt;
&lt;p&gt;Actually I think the real difference in these is the templates for projects you create and the emulators you are provided with. Professional, or Pocket PC, provides emulators for bigger screens. Microsoft has &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=06111A3A-A651-4745-88EF-3D48091A390B&amp;amp;displaylang=en"&gt;this to say&lt;/a&gt; about the naming kerfuffle:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
With Windows Mobile 6, we are revising our SKU taxonomy and naming to better align our brand and products with the realities of today&amp;rsquo;s mobile device marketplace. The historical form-factor based distinction between Windows Mobile powered Smartphone and Windows Mobile powered Pocket PC Phone Edition is blurring dramatically. We want our taxonomies and terminology to evolve to better reflect the evolution of the mobile device industry.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So in order to reflect the blurring of the mobile device form factors, they&amp;rsquo;ve changed from having SDKs named after the types of device to SDKs named &amp;ldquo;Standard&amp;rdquo; and &amp;ldquo;Professional&amp;rdquo;. Hmm. How about having a single SDK called &amp;ldquo;Mobile Device SDK&amp;rdquo; and allow me to pick the device dimensions from within my project on the fly? Back at the start of this tale, I assumed that picking Windows Mobile for development would allow us to target a range of different devices, large and small, and in fact I can do that. I can deploy my application to a Windows Mobile phone with a big screen and to one with a small screen. The SDK split seems pretty artificial with that in mind.&lt;/p&gt;
&lt;p&gt;Naming conventions and confusions aside, it is nice to be able to write against a single API and deploy to any Windows Mobile device. Or it would be if it worked.&lt;/p&gt;
&lt;p&gt;My bugbear here is with a particular class: CameraCaptureDialog. Take the Samsung Omnia for example. You can certainly pop up the camera using CCD.ShowDialog(), but can you retrieve the filename of the image you took? You cannot. That&amp;rsquo;s because the Omnia&amp;rsquo;s camera supports taking multiple images one after the other until you explicitly close it.&lt;/p&gt;
&lt;p&gt;How about the HTC Diamond? Well that opens fine, and returns a filename too, but if you try and re-open the camera straight after processing the filename, to allow the user to take another photo, it fails silently and doesn&amp;rsquo;t show the camera. If you try and do the same thing with the HTC Touch, it freezes.&lt;/p&gt;
&lt;p&gt;Part of the issue is that the Compact Framework leaves too much up to the manufacturers and doesn&amp;rsquo;t give enough control to the developer. We can set the resolution of the camera for example, but we have no shortcut of setting it to the maximum resolution available. If you try and set it to a resolution which is not supported, some devices reset silently to a much lower resolution.&lt;/p&gt;
&lt;p&gt;Microsoft need to extend camera support for .NET developers and give a lower level of access. They need to push device manufacturers to adhere to the Windows Mobile APIs and be more precise in how they are specified. And they need to simplify and modernise their mobile development framework so that developers can be fully aware of all the options available to them.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;This post was also published on &lt;a title="The State of WIndows Mobile" href="http://colinramsay.co.uk/diary/2009/01/14/the-state-of-windows-mobile/"&gt;my personal blog&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=The+State+of+Windows+Mobile&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2009%2f01%2f14%2fthe-state-of-windows-mobile.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2009%2f01%2f14%2fthe-state-of-windows-mobile.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=13380" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author><category term="windows mobile" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/windows+mobile/default.aspx" /><category term="compact framework" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/compact+framework/default.aspx" /></entry><entry><title>Parsing XML-like Files</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2008/12/07/parsing-xml-like-files.aspx" /><id>/blogs/colin_ramsay/archive/2008/12/07/parsing-xml-like-files.aspx</id><published>2008-12-07T10:23:00Z</published><updated>2008-12-07T10:23:00Z</updated><content type="html">&lt;p&gt;The quantity of data now stored in XML, HTML, and other similar formats must now be absolutely huge. Fetching that data from XML-like files is largely seen as a solved problem on many platforms, but I&amp;#39;m going to look at the various alternatives and see where each would be appropriate and how you can improve the development process by using each method.&lt;/p&gt;
&lt;h2&gt;The Manual Method&lt;/h2&gt;
&lt;p&gt;This is the one which makes me go *yuck* in a bit way. You can read in a file as a straightforward string or array of line strings, and skip to the part of the document you want. This is most definitely the manual method when it comes to parsing XML, because you&amp;#39;re not really taking an interest in whether the document&amp;#39;s XML or not. You&amp;#39;re not takin advantage of the structure and you&amp;#39;re treeating the file in the same way you would any flat file.&lt;/p&gt;
&lt;p&gt;I saw this approach in a PHP application, and it was being used to parse HTML. In this environment I can kind of understand why you&amp;#39;d think about the manual method: PHP doesn&amp;#39;t have a built in means of parsing XML into HTML, so there&amp;#39;s no way of getting a structured document to even use PHP&amp;#39;s DOM support with. However, there are third-party libraries which support methods which are a bit less laborious.&lt;/p&gt;
&lt;h2&gt;Taming HTML&lt;/h2&gt;
&lt;p&gt;Many platforms have libraries which parse HTML into a well-formed state to allow further processing. In fact, using HTML Tidy, you can do this manually from pretty much any platform. Some libraries will &lt;a href="http://www.devx.com/dotnet/Article/20505/0/page/2"&gt;wrap HTML Tidy&lt;/a&gt; and some will provide &lt;a href="http://www.codeplex.com/htmlagilitypack"&gt;their own method&lt;/a&gt;, but the bottom line is that you&amp;#39;re likely to be able to leverage some tool to tame the horrific mess of HTML that is the world wide web.&lt;/p&gt;
&lt;h2&gt;
XPATH
&lt;/h2&gt;
&lt;p&gt;With your HTML under control, or your XML at the ready, you&amp;#39;ve now got a chance to pull data from your document with some more advanced techniques. Most developers will have touched on XPATH at some time or another, as it&amp;#39;s commonplace within the ecosystems of most development platforms. The name gives it away - XPATH is XML Path Language, and allows the use of specialized queries to pull out parts of an XML document:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;//li&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This XPATH expression specifies that we wish to find all &amp;lt;li&amp;gt; elements at any level of the document. More complex expressions are available, providing means of selecting elements based on attributes, values of nodes, and much more. The strength of XPATH is its availability. In the .NET world, for example, fast XML processing and XPATH are available as first-class members of the framework, only a using directive away. This makes the use of XPATH common-place.&lt;/p&gt;
&lt;h2&gt;CSS Selectors&lt;/h2&gt;
&lt;p&gt;This alternative approach is less common due to the lack of first-class support in most frameworks. However, choice is good, so let&amp;#39;s look at the way in which CSS can pull out data from your XML documents. I suspect there are still developers out there with an aversion to CSS, so let&amp;#39;s be clear: this approach discusses CSS selectors, not layout with CSS. That means all of the strange behavious with comes with floating elements is not applicable here. We&amp;#39;re also not running CSS in the browser, so there are no incompatibility issues. This is a subset of CSS, working as advertised.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://code.whytheluckystiff.net/hpricot/"&gt;Hpricot&lt;/a&gt; for Ruby, &lt;a href="http://code.google.com/p/phpquery/"&gt;phpQuery&lt;/a&gt; for PHP and &lt;a href="http://code.google.com/p/fizzler/"&gt;my own Fizzler for .NET&lt;/a&gt; are examples of this kind of solution. Here&amp;#39;s a simple sample using Fizzler:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;var engine = new Fizzler.Parser.SelectorEngine(html);
engine.Parse(&amp;quot;.content&amp;quot;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We start up Fizzler by passing in some HTML string, and then select any nodes with a class name of &amp;quot;content&amp;quot;. Fizzler uses HTML Agility Pack underneath, so the result comes back as a collection of nodes which you can further manipulate. &lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;My rationale for developing Fizzler was a personal dislike of XPATH. Because I was strongly familiar with CSS, and because Fizzler supports some advanced CSS 3 selectors, it&amp;#39;s possible for me to achieve the same results using CSS selectors without the barrier for entry presented by XPATH. Your mileage may vary, depending on your experience with each technology, but Fizzler fills a gap in the .NET market and I hope some people will find it useful.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Parsing+XML-like+Files&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f12%2f07%2fparsing-xml-like-files.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f12%2f07%2fparsing-xml-like-files.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=8785" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author><category term="xml" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/xml/default.aspx" /><category term="xpath" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/xpath/default.aspx" /><category term="fizzler" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/fizzler/default.aspx" /><category term="html" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/html/default.aspx" /><category term="css" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/css/default.aspx" /></entry><entry><title>Open Source Documentation</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2008/11/23/open-source-documentation.aspx" /><id>/blogs/colin_ramsay/archive/2008/11/23/open-source-documentation.aspx</id><published>2008-11-23T15:49:00Z</published><updated>2008-11-23T15:49:00Z</updated><content type="html">&lt;p&gt;Recently I&amp;#39;ve set up a network attached storage computer on my home network. As well as providing RAID storage for all the devices in the house, it acts as a central download server for everyone to use. Key to this strategy is &lt;a href="http://www.sabnzbd.org/"&gt;SABnzbd&lt;/a&gt;, a Python application which downloads binaries from newsgroups, and which sits on the server as a daemon, grabbing files on a schedule or when we ask it to. The functionality of this software is incredible, but more than that, there is a great deal of documentation for each feature directly linked from the web interface. This enabled me to set up advanced features such as RSS feeds, categorisation, and post-download scripts, in order to shift SABnzbd from being handy to indispensible.&lt;/p&gt;
&lt;p&gt;This post is not about SABnzbd though - it&amp;#39;s about documentation. My latest project has been a very quick CMS solution using Monorail, and I&amp;#39;ve been taking advantage of the new features available in Castle&amp;#39;s trunk. The new routing in Monorail, the fluent API for component registration in Microkernel, and more new features, have all been making my life easier... once I&amp;#39;ve figured them out. I&amp;#39;m in awe of the people who have produced these features and I&amp;#39;m not adverse to digging round test cases where I can, in order to find out how to use them. &lt;/p&gt;
&lt;p&gt;However, it would unarguably be better if the Castle documentation reflected these new changes. It&amp;#39;s understandable that the documention lags behind these features, and since I don&amp;#39;t have the intimate Castle knowledge needed to contribute to fixing bugs or adding new code, I figured it&amp;#39;d be good to try and work on this documentation. Castle uses an &lt;a href="http://castleproject.org/community/getinvolved.html#documentation"&gt;XML based documentation format&lt;/a&gt; which is just fine for final docs, but not that great for scrabbling down notes and filling out information. For that, I&amp;#39;ve decided to use the using.castleproject.org wiki, a site designed to hold tips and tricks for the Castle Project.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve set up a &lt;a href="http://using.castleproject.org/display/CASTLE/Helping+With+Documentation"&gt;simple system of tagging&lt;/a&gt; which allows people to search out stuff in need of documentation and then tag it when it&amp;#39;s complete. At that point, I plan on converting it into a patch for the official Castle documentation. In this way we can get the rapid prototyping of a wiki combined with an easy route to formal documentation. I think barrier for entry is a definite problem for contributing on many projects, and documentation can be a good place to start. For Castle, I&amp;#39;m trying to make even the barrier for entry for even that documentation very low. So if you can help out with the &lt;a href="http://using.castleproject.org/display/MR/Routing+Overview"&gt;routing documentation&lt;/a&gt; or the &lt;a href="http://using.castleproject.org/display/MR/Monorail+Validation"&gt;validation documentation&lt;/a&gt; or anything else that&amp;#39;s missing or incomplete in the &lt;a href="http://castleproject.org/"&gt;main Castle docs&lt;/a&gt;, please pitch in and try and help! &lt;/p&gt;
&lt;p&gt;(Also published on &lt;a href="http://colinramsay.co.uk/diary/2008/11/23/open-source-documentationopen-source-documentation/%20"&gt;my personal blog&lt;/a&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Open+Source+Documentation&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f11%2f23%2fopen-source-documentation.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f11%2f23%2fopen-source-documentation.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=7198" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author></entry><entry><title>Common Interfaces for Tool Families</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2008/11/13/common-interfaces-for-tool-families.aspx" /><id>/blogs/colin_ramsay/archive/2008/11/13/common-interfaces-for-tool-families.aspx</id><published>2008-11-13T10:05:00Z</published><updated>2008-11-13T10:05:00Z</updated><content type="html">&lt;p&gt;There are a load of different tool &amp;quot;families&amp;quot; in use in the .NET ecosystem which I&amp;#39;m sure LosTechies readers will take advantage of pretty much every day. IoC containers. Logging infrastructures. URL routing mechanisms. Each of these families operate on broadly similar principals - taking the container example, we know that we need to add types to the container and resolve types which are already in there. For logging, we&amp;#39;d generally have the ability to log to different levels of severity. So you can see that while the implementations and underlying behaviour may be significantly different, there is a layer of abstraction which highlights commonality.&lt;/p&gt;
&lt;p&gt;Castle Project has a Castle.Core.Logging.ILogger class which supports the use of a variety of different logging systems within your applications. It is a facade behind which log4net or NLog does the magic while your application happily logs information while not worrying about what is actually taking care of the logging. To me, this is a very interesting method of supporting a tool family - expose the most common methods which a tool supports and let the tool get on with its own business.&lt;/p&gt;
&lt;p&gt;What I&amp;#39;d like to see is a community effort to publish an ILogger interface to which various logging libraries can adhere, and an IContainer interface for IoC libraries, and other interfaces for various tool families which have enough common features. In this way, we can enable a new level of code sharing and integration between projects.&lt;/p&gt;
&lt;p&gt;(Also published on &lt;a href="http://colinramsay.co.uk/diary/2008/11/16/common-interfaces-for-tool-families/"&gt;my personal blog&lt;/a&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Common+Interfaces+for+Tool+Families&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f11%2f13%2fcommon-interfaces-for-tool-families.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f11%2f13%2fcommon-interfaces-for-tool-families.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=6213" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author><category term="softwaredesign" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/softwaredesign/default.aspx" /></entry><entry><title>Application Configuration</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2008/11/12/application-configuration.aspx" /><id>/blogs/colin_ramsay/archive/2008/11/12/application-configuration.aspx</id><published>2008-11-12T21:13:00Z</published><updated>2008-11-12T21:13:00Z</updated><content type="html">&lt;p&gt;I had cause to recently revisit an old ASP.NET application I&amp;#39;d written way back when I was a development newcomer. Digging around the web.config I found the appSettings section:&lt;/p&gt;
&lt;pre&gt;&amp;lt;appSettings&amp;gt;&lt;br /&gt;    &amp;lt;add key=&amp;quot;systemEmailAddress&amp;quot; value=&amp;quot;me@me.com&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&amp;quot;adminEmailAddress&amp;quot; value=&amp;quot;me@me.com&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&amp;quot;templateDirectory&amp;quot; value=&amp;quot;~/admin/templates/&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&amp;quot;installPath&amp;quot; value=&amp;quot;~/admin/&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/appSettings&amp;gt;&lt;/pre&gt;
&lt;p&gt;You get the idea. There were loads of these, configuring many different aspects of the system. Many should have been configurable by site administrators from some kind of user interface. Technically this is possible - editing the web.config on the fly - but I really wouldn&amp;#39;t recommend it. &lt;/p&gt;
&lt;p&gt;Anyway, since then I&amp;#39;ve used this method a number of times, as well as having a Settings database table which stores key/value pairs:&lt;/p&gt;
&lt;pre&gt;var email = SettingRepository.FindByKey(&amp;quot;email&amp;quot;);&lt;/pre&gt;
&lt;p&gt; Or having a Settings table with a single row and columns for each setting to allow it to be mapped to an object:&lt;/p&gt;
&lt;pre&gt;Settings settings = SettingsRepository.FindFirst();&lt;/pre&gt;
&lt;p&gt; All three have upsides and downsides but none are particularly satisfying. I&amp;#39;m mulling over which approach to take in my next project which is going to need a fair few of these settings. Which method do you favour? Do you have a fourth way?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Application+Configuration&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f11%2f12%2fapplication-configuration.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f11%2f12%2fapplication-configuration.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=6187" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author><category term="configuration" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/configuration/default.aspx" /></entry><entry><title>Your Development Environment</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2008/06/13/your-development-environment.aspx" /><id>/blogs/colin_ramsay/archive/2008/06/13/your-development-environment.aspx</id><published>2008-06-13T10:00:00Z</published><updated>2008-06-13T10:00:00Z</updated><content type="html">&lt;p&gt;When I first started working in &amp;quot;the real world&amp;quot;, I had a development environment which I&amp;#39;d describe as typical: average Dell computer and peripherals, one monitor, Windows XP with all my applications installed, including VS2003 and VS2005. I&amp;#39;m sure&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Last year, when I struck out on my own to start Plastiscenic, I knew I needed an upgrade. For starters, my XP install was grinding to a halt. But I was also concerned about the way all of my interests were intermingling - games, hobby stuff and professional stuff all on the same installation. That felt pretty bad to me, not least because Windows XP gets very sluggish after a few months with lots of programs installed.&lt;/p&gt;&lt;p&gt;I purchased an Intel Q6600 with 4Gb of RAM, and a 10k RPM boot drive. That was stage one. I set up two monitors on a bigger desk with a lamp on it to reduce any strain on my eyes. I installed Vista 64 Business Edition, which I felt was a better match for the hardware than XP. The core setup was there, but there was still a key component missing.&lt;/p&gt;&lt;p&gt;VMWare provided the answer. By creating a stripped down Windows XP installation I had a fast virtual machine to install development software on. I had another VM for SQL Server. These trim virtual machines could be backed up with ease, and moved offsite if need be. If my main machine died, I only had to reinstall a basic environment and VMWare Player to become productive again.&lt;/p&gt;&lt;p&gt;In a larger team of developers, such virtualisation software provides even more options. An administrator could provide base images which can be served across a network, giving developers tailored environments within a few clicks. This is good for testing too - prepare images for a multitude of operating systems for pre-production testing of a desktop application.&lt;/p&gt;&lt;p&gt;I believe virtualisation will become even more popular over the next few years, giving us more opportunities to create sandboxed environments which can be run at the click of the mouse.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Your+Development+Environment&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f06%2f13%2fyour-development-environment.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f06%2f13%2fyour-development-environment.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=3498" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author></entry><entry><title>Design Dithering</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2008/06/02/design-dithering.aspx" /><id>/blogs/colin_ramsay/archive/2008/06/02/design-dithering.aspx</id><published>2008-06-02T18:40:00Z</published><updated>2008-06-02T18:40:00Z</updated><content type="html">&lt;p&gt;When you break out of the &amp;quot;new programmer&amp;quot; mindset and begin thinking in terms of organisation, patterns, and good design, I think there&amp;#39;s a real danger of hitting a development wall. What actually is the correct way of implementing a shopping cart? Should you use a three or four tier application design? My outlook on this is pretty simple:&lt;/p&gt;&lt;p&gt;It doesn&amp;#39;t matter.&lt;/p&gt;&lt;p&gt;The &lt;a href="http://www.domaindrivendesign.org/books/index.html#DDD"&gt;Domain Driven Design book&lt;/a&gt; teaches a lot of interesting stuff, some of which can contribute to a brain freeze. So many new concepts can mean that there are a lot of possible avenues of approach for any given problem. But in my eyes, one of the most valuable lessons that Eric Evans gives in that book is that refactoring is key. If I find myself struggling to adapt the right approach, I take the simplest route, safe in the knowledge that if I&amp;#39;ve done it wrong, my application will let me know, big time. If I&amp;#39;m following a loosely coupled design, no single refactoring should have a huge impact on the rest of the application.&lt;/p&gt;&lt;p&gt;So if you find that you&amp;#39;re struggling for a solution, take the simplest, quickest - even do a dirty hack! - and know that next week, if that decision comes back to bite you, you can just refactor it out. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Design+Dithering&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f06%2f02%2fdesign-dithering.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f06%2f02%2fdesign-dithering.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=3496" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author><category term="practices pragmatism" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/practices+pragmatism/default.aspx" /></entry><entry><title>Javascript Patterns &amp; Practices</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2008/01/17/javascript-patterns-amp-practices.aspx" /><id>/blogs/colin_ramsay/archive/2008/01/17/javascript-patterns-amp-practices.aspx</id><published>2008-01-17T22:17:00Z</published><updated>2008-01-17T22:17:00Z</updated><content type="html">&lt;p&gt;My previous post on Javascript gave an insight into using the language in a more structured manner than you may 

have been used to in the past. I&amp;#39;m going to talk about a few more methods which I use a lot, and that help me keep 

my JS workable.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Pattern&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Last time, I talked about the Object Literal pattern. If it helps, you can think about this as if it were a C# 

static class; you don&amp;#39;t need to instantiate it, it can have state, but it is application-wide. I will typically use 

Object Literal as a kind of &amp;quot;manager&amp;quot;, which controls what happens on a page, from a function which fires onload, 

to functions which get triggered on button clicks.&amp;nbsp;&lt;/p&gt;

&lt;p&gt;In other places, such as complex user interfaces, I will typically need &amp;quot;components&amp;quot;, which wrap up a lot of 

functionality and may be used multiple times within a page. An example of this might be a date picker control. For 

these components, I need to hold state, and so I need the equivalent of a standard C# class.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function DatePicker(date) {&lt;br /&gt;&lt;br /&gt;	if(date) {&lt;br /&gt;		this.initial = date;&lt;br /&gt;	} else {&lt;br /&gt;		this.initial = new Date();&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	this.show = function(date) {&lt;br /&gt;		alert(this.initial);&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;var startDatePicker = new DatePicker();&lt;br /&gt;var endDatePicker = new DatePicker(new Date(&amp;#39;Jan 1, 2009&amp;#39;));&lt;br /&gt;&lt;br /&gt;startDatePicker.show();&lt;br /&gt;endDatePicker.show();&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this example, startDatePicker gets instantiated with a default date, but endDatePicker gets a different date 

passed in its &amp;quot;constructor&amp;quot;. You can see that both objects retain their own state when the show() functions get 

called and different dates are alerted.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Practise&lt;/b&gt;&lt;/p&gt;

You can do faux-namespaces in Javascript as well as faux-classes. I use them to package up related code and 

partition it, much as you might do with namespacing in other languages. There are a number of different ways of 

providing this functionality, and here&amp;#39;s one which is incredibly simple:

&lt;pre&gt;&lt;code&gt;var NAMESPACE = {};&lt;br /&gt;NAMESPACE.utils = {};&lt;br /&gt;NAMESPACE.interface = {}; // other namespaces&lt;br /&gt;&lt;br /&gt;NAMESPACE.utils.fixIE = function() {&lt;br /&gt;// code&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;NAMESPACE.utils.fixIE();&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Other ways of organising your 
javascript code can be pulled directly from C# best-practises, such as one-class-

per-file. Another beneficial approach is to avoid embedding your javascript code in your HTML. Code like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;a href=&amp;quot;/javascriptrequired.aspx&amp;quot; id=&amp;quot;showPicker&amp;quot; onclick=&amp;quot;showDatePicker();&amp;quot;&amp;gt;Pick Date&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Can often be easier to maintain when written &amp;quot;unobtrusively&amp;quot;, with the following in a linked JS file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var document.getElementById(&amp;#39;showPicker&amp;#39;).onclick = showDatePicker;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And now this in your HTML:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;a href=&amp;quot;/javascriptrequired.aspx&amp;quot; id=&amp;quot;showPicker&amp;quot; &amp;amp;gtPick Date&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This keeps your javascript confined to .js files and out of the HTML, which is generally a cleaner approach.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Further Reading&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;You can continue to develop well by &lt;a href="http://www.jsunit.net/"&gt;unit testing your javascript&lt;/a&gt; and &lt;a href="http://jsdoc.sourceforge.net/"&gt;documenting&lt;/a&gt; it fully. You can also &lt;a href="http://www.jslint.com/"&gt;check it for errors&lt;/a&gt; and then &lt;a href="http://alex.dojotoolkit.org/shrinksafe/"&gt;compress it&lt;/a&gt; for deployment. Javascript is an important tool in your arsenal; use it well!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Javascript+Patterns+%26amp%3b+Practices&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f01%2f17%2fjavascript-patterns-amp-practices.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2008%2f01%2f17%2fjavascript-patterns-amp-practices.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=1830" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author><category term="javascript" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/javascript/default.aspx" /><category term="practices" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/practices/default.aspx" /></entry><entry><title>You Have Nothing To Fear From Javascript</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2007/12/08/you-have-nothing-to-fear-from-javascript.aspx" /><id>/blogs/colin_ramsay/archive/2007/12/08/you-have-nothing-to-fear-from-javascript.aspx</id><published>2007-12-08T10:46:00Z</published><updated>2007-12-08T10:46:00Z</updated><content type="html">&lt;p&gt;Building a web application consists of a number of discrete layers: server code, client code, HTML, and styling. If you cannot sit down with one of those layers and work on it, you are not fulfilling your role. If I hire a web developer, I don&amp;#39;t expect them to tell me that they know little of Javascript, but unfortunately there seems to be a fear of that language, where people are happy to hide it away behind a facade of server-side code which autogenerates it.&lt;/p&gt;&lt;p&gt;This is &lt;i&gt;wrong&lt;/i&gt;. If you are working with Javascript, client side code, then you should be able to fully debug, understand, and tweak that code natively. Changing some C# code which you think will generate the right JS is such a horrific approach I can&amp;#39;t believe anyone would advocate it. In order to have a robust application you need full control of all aspect, from top to bottom.&lt;/p&gt;&lt;p&gt;Besides, Javascript is actually a &lt;i&gt;great&lt;/i&gt; language, though much maligned over the years. As the web matured, Javascript was often responsible for scrolling banners, page errors, and other affronts to the user. But as people have documented its browser support and language tricks, Javascript has matured with its environment. Check out this structure in BLOCKED SCRIPT&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// Setup &amp;quot;static&amp;quot; structure&lt;br /&gt;var Application = function() {&lt;br /&gt;&lt;br /&gt;	var _privateVar = 0; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;	return {&lt;br /&gt;&lt;br /&gt;		someFunction : function() {&lt;br /&gt;			_privateVar = 5;&lt;br /&gt;&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;	}&lt;br /&gt;    } &lt;br /&gt;}();&lt;br /&gt;&lt;br /&gt;// Run the function&lt;br /&gt;Application.someFunction();&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Organised, readable Javascript! Whatever next! You can even have psuedo-namespaces, classes, anonymous functions, loads of great dynamic language features which allow you to come up with flexible and concise code. Generating your JS isn&amp;#39;t just unwise, it means you&amp;#39;re missing out on all the fun! &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=You+Have+Nothing+To+Fear+From+Javascript&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2007%2f12%2f08%2fyou-have-nothing-to-fear-from-javascript.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2007%2f12%2f08%2fyou-have-nothing-to-fear-from-javascript.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=1512" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author><category term="javascript" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/javascript/default.aspx" /></entry><entry><title>Working with Interfaces Part Three - Windsor</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2007/11/21/working-with-interfaces-part-three-windsor.aspx" /><id>/blogs/colin_ramsay/archive/2007/11/21/working-with-interfaces-part-three-windsor.aspx</id><published>2007-11-21T18:00:00Z</published><updated>2007-11-21T18:00:00Z</updated><content type="html">&lt;p&gt;&lt;a href="http://www.castleproject.org/container/index.html"&gt;Castle Windsor&lt;/a&gt; is an &lt;a href="http://www.betaversion.org/%7Estefano/linotype/news/38/"&gt;Inversion of Control&lt;/a&gt; container which uses interfaces as a key concept. When working in the manner I described in my previous articles on interfaces, you get a decoupled application but may end up with a lot of &amp;quot;wiring-up&amp;quot; - instantiating interface implementations then passing them into your classes.&lt;/p&gt;  &lt;p&gt;For example, a Controller may often demand an implementation of ILogger, IAuthenticationService, IRepository and IPaymentGateway, which would require a fair bit of code to wire up. Windsor removes the wire up burden from the developer. Using XML configuration, you can easily swap out one implementation for another:&lt;/p&gt;  &lt;pre&gt;&lt;code&gt;public interface ISport{}&lt;br /&gt;public class Football : ISport{}&lt;br /&gt;&lt;br /&gt;&amp;lt;component id=&amp;quot;default.sport&amp;quot;&lt;br /&gt;	service=&amp;quot;ISport, WindsorTest&amp;quot;&lt;br /&gt;	type=&amp;quot;Football, WindsorTest&amp;quot;/&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this example, we use the &lt;a href="http://www.castleproject.org/container/documentation/trunk/usersguide/externalconfig.html"&gt;component element&lt;/a&gt; to wire up the Football implementation for any usage of ISport. For Windsor to provide this ISport implementation to your consuming classes, the consumer needs to be in the container too:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;public class Consumer&lt;br /&gt;{&lt;br /&gt;	// Parameter injection&lt;br /&gt;	public ISport Sport{ get; set; }&lt;br /&gt;	// Constructor injection&lt;br /&gt;	public Consumer(ISport sport){} &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&amp;lt;component id=&amp;quot;some.consumer&amp;quot; type=&amp;quot;Consumer, WindsorTest&amp;quot;/&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So now Consumer will have the configured ISport passed to its constructor or the Sport parameter, depending on your preference. We could also have an ISport parameter on Consumer and Windsor would be able to set it with the configured implementation of ISport.&lt;/p&gt;

&lt;p&gt;Using a system like Windsor is a logical extension of the practises I&amp;#39;ve talked about before. It gives you the flexibility of interfaces without the burden of having to manually instantiate and pass through all of the implementations your classes may depend upon. When thinking about &lt;a href="http://www.domaindrivendesign.org/"&gt;Domain Driven Design&lt;/a&gt;, you can use Windsor to provide Services to your application, allowing it to &lt;a href="http://omnomnomnom.com/"&gt;consume&lt;/a&gt; independent components and create &lt;a href="http://photos1.blogger.com/blogger/7184/598/1600/DiamondMine031.jpg"&gt;one awesome whole&lt;/a&gt;. Full Windsor documentation can be found on the &lt;a href="http://www.castleproject.org/container/documentation/trunk/index.html"&gt;Castle website&lt;/a&gt;, and I&amp;#39;ve also written about Windsor on my &lt;a href="http://colinramsay.co.uk/category/windsor/"&gt;personal blog&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Working+with+Interfaces+Part+Three+-+Windsor&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2007%2f11%2f21%2fworking-with-interfaces-part-three-windsor.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2007%2f11%2f21%2fworking-with-interfaces-part-three-windsor.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=1421" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author></entry><entry><title>Working with Interfaces Part Two - Decoupling</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2007/10/09/working-with-interfaces-part-one-decoupling.aspx" /><id>/blogs/colin_ramsay/archive/2007/10/09/working-with-interfaces-part-one-decoupling.aspx</id><published>2007-10-09T20:47:00Z</published><updated>2007-10-09T20:47:00Z</updated><content type="html">&lt;p&gt;In the first part of this mini-series I talked about the basic use of interfaces, which is to provide a contract for your developers to work to. In this part, I&amp;#39;m going to try and demonstrate how interfaces can be used to make your application more flexible. This is probably the most common type of tutorial on interfaces you&amp;#39;ll see around the web, so forgive me for adding another.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s an example of traditional style development, without interfaces:&lt;/p&gt;&lt;code&gt;&lt;pre&gt;public class YoGenerator
{
	public string Generate()
	{
		return &amp;quot;yo!&amp;quot;;
	}
}

public class Greeter
{
	public void SaySomething()
	{
		YoGenerator yoGenerator = new YoGenerator();
		
		Console.WriteLine(yoGenerator.Generate());
	}
}

public class Program
{
	public static void Main()
	{
		new Greeter().SaySomething();
	}
}&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;So we&amp;#39;ve got a program that creates a new Greeter class and calls the SaySomething method on it. The Greeter class in turn calls a YoGenerator&amp;#39;s Generate method to output &amp;quot;yo!&amp;quot; to the console. This should all be fairly straightforward so far and if not, well, you&amp;#39;ve got bigger worries than what an interface is for.&lt;/p&gt;
&lt;p&gt;So, the first step on making this a more useful application (I say that in the loosest terms, I&amp;#39;m not sure how much mileage you can get out of an app that says &amp;quot;yo!&amp;quot;) is to refactor by extracting an interface from the YoGenerator class and make YoGenerator inherit it:&lt;/p&gt;&lt;code&gt;&lt;pre&gt;public interface IGreetingGenerator
{
	string Generate();
}

public class YoGenerator : IGreetingGenerator
{
	public string Generate()
	{
		return &amp;quot;yo!&amp;quot;;
	}
}&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;In terms of what our app now does, nothing has changed. It still outputs &amp;quot;yo!&amp;quot; to the console and it still does it using the same mechanism. However, we can now make an additional change which opens up more options:&lt;/p&gt;&lt;code&gt;&lt;pre&gt;public class Greeter
{
	public void SaySomething(IGreetingGenerator greetingGenerator)
	{
		Console.WriteLine(greetingGenerator.Generate());
	}
}
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;That&amp;#39;s a fairly big jump if you&amp;#39;re not familiar with interfaces. We&amp;#39;re saying that SaySomething now takes one parameter - an instance of a class which implements IGreetingGenerator. That&amp;#39;s an important piece of information, because while you can&amp;#39;t directly create a new instance of IGreetingGenerator, you can pass implementing classes round in this way. And because IGreetingGenerator defines a method Generate, we&amp;#39;re able to call that on the instance we&amp;#39;re passing in. The final piece of the puzzle involves supplying SaySomething with an instance of a class that implements IGreetingGenerator. And remember how we changed YoGenerator to implement IGreetingGenerator...?&lt;/p&gt;&lt;code&gt;&lt;pre&gt;public class Program
{
	public static void Main()
	{
		new Greeter().SaySomething(new YoGenerator());
	}
}&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;So we instantiate a new YoGenerator which is also typeof IGreetingGenerator, and pass that to SaySomething. In the process, we&amp;#39;ve extracted SaySomething&amp;#39;s dependancy on YoGenerator... What does that mean for us? Well it means we can pass in new greeting generators to affect the behaviour of SaySomething, without actually having to change SaySomething&amp;#39;s code:&lt;/p&gt;&lt;code&gt;&lt;pre&gt;public class DrunkenGreetingGenerator : IGreetingGenerator
{
	public string Generate()
	{
		return &amp;quot;i lovzshh u mannn!!?!&amp;quot;;
	}
}

public class Program
{
	public static void Main()
	{
		new Greeter().SaySomething(new DrunkenGreetingGenerator());
	}
}&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;With a bit of forward thinking we can make the Greeter class work independently of other classes - we&amp;#39;ve &lt;em&gt;decoupled&lt;/em&gt; it from YoGenerator and given it freedom to work with any class that implements IGreetingGenerator.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Working+with+Interfaces+Part+Two+-+Decoupling&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2007%2f10%2f09%2fworking-with-interfaces-part-one-decoupling.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2007%2f10%2f09%2fworking-with-interfaces-part-one-decoupling.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=931" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author><category term="c# practices interfaces" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/c_2300_+practices+interfaces/default.aspx" /></entry><entry><title>Why ALT.NET?</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2007/10/08/why-alt-net.aspx" /><id>/blogs/colin_ramsay/archive/2007/10/08/why-alt-net.aspx</id><published>2007-10-08T10:56:00Z</published><updated>2007-10-08T10:56:00Z</updated><content type="html">&lt;p&gt;DISCLAIMER: This post was inspired by, and contains material from,&amp;nbsp;a recent post on my personal blog entitled &amp;quot;&lt;a class="" title="Abandon ALT.NET" href="http://colinramsay.co.uk/2007/10/07/abandon-altnet/" target="_blank"&gt;Abandon ALT.NET&lt;/a&gt;&amp;quot;.&lt;/p&gt;
&lt;p&gt;For a few months the term &amp;quot;ALT.NET&amp;quot; has been gaining traction on the blogs I read, starting from a post by &lt;a class="" href="http://laribee.com/blog/2007/04/10/altnet/" target="_blank"&gt;David Laribee&lt;/a&gt; in April. From there it has taken off, with an ALT.NET Conference taking place this week. So it’s perhaps timely that &lt;a class="" href="http://samgentile.com/" target="_blank"&gt;Sam Gentile&lt;/a&gt; has written a post entitled &amp;quot;&lt;a class="" href="http://samgentile.com/blogs/samgentile/archive/2007/10/06/goodbye-codebetter-and-alt-net.aspx" target="_blank"&gt;Goodbye CodeBetter and ALT.NET&lt;/a&gt;&amp;quot; which talks about the ALT.NET movement and some of the people surrounding it.&lt;/p&gt;
&lt;p&gt;I honestly don&amp;#39;t get the point of ALT.NET. While I use and appreciate a lot of the technologies and ideas which they&amp;#39;re pushing, I don&amp;#39;t see the value in wrapping it with a new moniker. This very act is one of segregation, because it pigeonholes people and technologies away from everything else. As Sam says, &amp;quot;ALT.NET is a divisive thing. No matter what they tell you.&amp;quot; Maybe this is a P.R. problem and maybe not. But perception is everything; not your perception but &lt;em&gt;how other people perceive you&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;One of the numerous sources of that negative perception is the frequent use of the term &amp;quot;Mort&amp;quot; by ALT.NET bloggers. I &lt;em&gt;strongly&lt;/em&gt; dislike this term, I mean &lt;em&gt;come on&lt;/em&gt;, the damn thing is short for &amp;quot;mortal&amp;quot;. That&amp;#39;s a pretty clear proclaimation that the people who aren&amp;#39;t &amp;quot;Morts&amp;quot; must be something more: not mere mortals, but Gods of their domain. Overseers of the lower developers who haven’t had the resources, or the guidance, to work with the fantastic array of non-Microsoft technologies that exist.&lt;/p&gt;
&lt;p&gt;You&amp;#39;re not going to address that imbalance by putting all of the people that already subscribe to your notions &lt;a class="" href="http://www.altnetconf.com/" target="_blank"&gt;in one place&lt;/a&gt;. I mean, think about it, DDD, BDD, MVC are&amp;nbsp;things which will be known, in some form or another, to the majority of the ALT.NET Conference attendees.&lt;/p&gt;
&lt;p&gt;ALT.NETter A: so… heard of that new BDD business?&lt;br /&gt;ALT.NETter B: Yep.&lt;br /&gt;ALT.NETter A: Oh, well there’s this great new idea called DDD!&lt;br /&gt;ALT.NETter B: Yeah, right into that too.&lt;br /&gt;ALT.NETter A: Oh.&lt;/p&gt;
&lt;p&gt;And so on. But wouldn’t that conversation have been a whole lot more interesting if the second developer &lt;em&gt;hadn’t&lt;/em&gt; heard of those ideas? Wouldn&amp;#39;t it make more sense to talk to the people who are really in need of your ideas and your tools and your knowledge?&lt;/p&gt;
&lt;p&gt;A lot of people in the ALT.NET camp may not feel that they’re being divisive but really, by propagating this idea you’re creating a line in the sand, with the highly-knowledgable on one side and the masses on the other. You’re not encouraging dissemination of your information, you’re just creating another impenetrable gang of developers that is almost opaque to the guy on the ground.&lt;/p&gt;
&lt;p&gt;The solution? Not to rename or rebrand, or even sharpen your mission statement. Instead break away from ALT.NET, walk among those mortals and share more of&amp;nbsp;your knowledge through the normal channels. It&amp;#39;s not as glamorous, but it will be a lot healthier in the long run.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Why+ALT.NET%3f&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2007%2f10%2f08%2fwhy-alt-net.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2007%2f10%2f08%2fwhy-alt-net.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=901" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author></entry><entry><title>Working with Interfaces Part One - Contracts</title><link rel="alternate" type="text/html" href="/blogs/colin_ramsay/archive/2007/10/01/working-with-interfaces-part-one-contracts.aspx" /><id>/blogs/colin_ramsay/archive/2007/10/01/working-with-interfaces-part-one-contracts.aspx</id><published>2007-10-01T21:15:00Z</published><updated>2007-10-01T21:15:00Z</updated><content type="html">&lt;p&gt;I hold my hands up - I am a programmer who doesn&amp;#39;t have a computer science background. My education only skimmed programming and was totally bereft of any architectural considerations. I almost stumbled into my first programming job, and I such I realise I have a lot of to learn about that which I use to earn a crust.&lt;/p&gt;
&lt;p&gt;One of the things that took me a while to appreciate was the power of interfaces. I specifically remember a conversation I had with my boss in which I said, baffled, &amp;quot;so... they don&amp;#39;t actually *do* anything then??&amp;quot;. And this is kind of true, interfaces don&amp;#39;t really &amp;quot;do&amp;quot; anything. Instead, they&amp;#39;re an enabler for a couple of really useful techniques.&lt;/p&gt;
&lt;p&gt;Imagine you&amp;#39;re creating a series of sub forms in a Windows application. They&amp;#39;re each supposed to do a similar thing and should always have methods to LoadSettings and SaveSettings. Something like this:&lt;/p&gt;&lt;code&gt;&lt;pre&gt;public class NamePrefs : Form
{
	public void LoadSettings(){}
	public void SaveSettings(){}
}&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;However, a new developer jumps in to your project and is instructed to create a new preferences form. They come up with something like this:&lt;/p&gt;&lt;code&gt;&lt;pre&gt;public class HeightPrefs : Form
{
	public void ExportConfigData(){}
}&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;For starters they&amp;#39;ve forgotten that the form needs to load up existing data and so hasn&amp;#39;t implemented loading functionality. Secondly, they&amp;#39;ve called their save method something different to the save method in all your other preference forms. Interfaces can provide a possible solution:&lt;/p&gt;&lt;code&gt;&lt;pre&gt;public interface IPreferencesForm
{
	void LoadSettings;
	void SaveSettings;
}&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;This interface is specifying a contract which implementing classes can adhere. Our initial example would look like:&lt;/p&gt;&lt;code&gt;&lt;pre&gt;public class NamePrefs : Form, IPreferencesForm
{
	....
}&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;If our second example also inherited from IPreferencesForm, that implementation would throw compiler errors as neither the LoadSettings or SaveSettings methods specified in the interface contract are present in the HeightPrefs class.&lt;/p&gt;
&lt;p&gt;Using interfaces only solves one part of the problem - you&amp;#39;ve got to make sure that people do actually inherit from them. That&amp;#39;s an issue which can be solved by enforcing developer policies, or technically, by ensuring only classes which implement the correct interface will get loaded by your main program. However, when interfaces are used in this manner, they can improve consistancy and lead to improved discoverability in your code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Working+with+Interfaces+Part+One+-+Contracts&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2007%2f10%2f01%2fworking-with-interfaces-part-one-contracts.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fcolin_ramsay%2farchive%2f2007%2f10%2f01%2fworking-with-interfaces-part-one-contracts.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=803" width="1" height="1"&gt;</content><author><name>cramsay</name><uri>http://www.lostechies.com/members/cramsay/default.aspx</uri></author><category term="c#" scheme="http://www.lostechies.com/blogs/colin_ramsay/archive/tags/c_2300_/default.aspx" /></entry></feed>