<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Mo Khan: My Blog! - Books</title>
    <link>http://mokhan.ca/blog/</link>
    <description>Update your gray matter, because one day it may matter!</description>
    <language>en-us</language>
    <copyright>Mo Khan</copyright>
    <lastBuildDate>Fri, 13 Mar 2009 19:56:23 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>mo@mokhan.ca</managingEditor>
    <webMaster>mo@mokhan.ca</webMaster>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=98f944bb-8b1b-4e35-9a0e-e0502f27fe20</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,98f944bb-8b1b-4e35-9a0e-e0502f27fe20.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently finished reading.
</p>
        <table>
          <tbody>
            <tr>
              <td>
                <a href="http://www.amazon.com/gp/product/1590596528?ie=UTF8&amp;tag=mokhthliofawa-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1590596528">
                  <img src="https://images-na.ssl-images-amazon.com/images/I/51v5h50rHaL._SL160_.jpg" border="0" />
                </a>
                <img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;l=as2&amp;o=1&amp;a=1590596528" width="1" border="0" />
              </td>
              <td>
                <a href="http://www.amazon.com/gp/product/1590596528?ie=UTF8&amp;tag=mokhthliofawa-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1590596528">Deploying
.NET Applications: Learning MSBuild and ClickOnce (Expert's Voice in .Net)</a>
                <img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;l=as2&amp;o=1&amp;a=1590596528" width="1" border="0" />
              </td>
            </tr>
          </tbody>
        </table>
        <p>
I was interested in this book mainly to find an easier way to deploy ClickOnce applications
via an automated build. Most of my build automation experience has been with Nant,
so I figured learning MSBuild couldn't hurt.
</p>
        <p>
This book targets the Visual Studio 2005 time frame, so some of the things that it
describes is out dated, mainly in regards to ClickCnce.
</p>
        <p>
There was a little coverage on mage.exe but not as much as I had liked. If you're
looking for a book to get you into the world of Clickonce or MSBuild, this one's pretty
good!
</p>
        <p>
Here are some of the things that I learned straight from the book. 
</p>
        <h3>MSBuild
</h3>
        <p>
Microsoft.Build.Framework and Microsoft.Build.Utilities contains some stuff to help
you with your builds. There's an ITask interface and a Task base class that you can
implement if you want to run some custom tasks from MSBuild.
</p>
        <p>
ClickOnce is driven by two XML-based manifest files called the deployment manifest
and the application manifest. 
</p>
        <ul>
          <li>
Deployment manifest (.application) contains information specific to the deployment
of the system. 
</li>
          <li>
Application manifest (.manifest) captures information specific to version of the system. 
</li>
        </ul>
        <h3>ClickOnce Deployment
</h3>
        <p>
The ClickOnce technology also has a programmatic interface that you can use to customize
deployment and updates. For example, if you have a plug-in where the core of the application
is deployed initially and then users are allowed to choose optional features (plug-ins)
and have them installed on demand, the ClickOnce API can help.
</p>
        <p>
ClickOnce applications have to be deployed to a Web server, to a file server, and/or
to removable media (such as CD/DVD). Moreover, you can deploy these applications in
one of two modes: offline or online.
</p>
        <p>
For applications that require finer-grained control over doing updates, application
authors can use the ClickOnce APIs to customize installation and updates.
</p>
        <h3>Code Access Security (CAS)
</h3>
        <ul>
          <li>
Permission: The authority to do something. 
</li>
          <li>
Permission set: A grouping of arbitrary permissions. 
</li>
          <li>
Origin based Evidence: Where your code comes from determines what permissions your
code gets. 
</li>
          <li>
Content base evidence: Your code content is signed and has a publisher certificate,
and that determines what permissions you get. 
</li>
          <li>
Code Group: Associates evidence with a permission set 
</li>
          <li>
Security Policy: Policies define a hierarchy of code groups. 
</li>
        </ul>
        <h3>On-Demand Download
</h3>
        <p>
ClickOnce offers a facility that called on-demand download. The idea is that you create
groups of files and then use the ClickOnce APIs to download each group at runtime.
The initial download is reduced to what is needs to be downloaded to run the application,
and if a piece of functionality is not needed, it is not downloaded.
</p>
        <p>
You can get the path to the Data directory via:
</p>
        <ul>
          <li>
            <div style="font-size: 14pt; background: black; color: white; font-family: consolas">
              <pre style="margin: 0px">
                <span style="color: yellow">AppDomain</span>.CurrentDomain.GetData(<span style="color: lime">"DataDirectory"</span>);</pre>
            </div>
          </li>
          <li>
            <div style="font-size: 14pt; background: black; color: white; font-family: consolas">
              <pre style="margin: 0px">
                <span style="color: yellow">ApplicationDeployment</span>.CurrentDeployment.DataDirectory;</pre>
            </div>
          </li>
          <li>
            <div style="font-size: 14pt; background: black; color: white; font-family: consolas">
              <pre style="margin: 0px">
                <span style="color: yellow">Application</span>.LocalUserAppDataPath;</pre>
            </div>
          </li>
        </ul>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=98f944bb-8b1b-4e35-9a0e-e0502f27fe20" />
      </body>
      <title>Deploying .NET Applications &amp;ndash; Learning MSBuild and ClickOnce</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,98f944bb-8b1b-4e35-9a0e-e0502f27fe20.aspx</guid>
      <link>http://mokhan.ca/blog/2009/03/13/Deploying+NET+Applications+Ndash+Learning+MSBuild+And+ClickOnce.aspx</link>
      <pubDate>Fri, 13 Mar 2009 19:56:23 GMT</pubDate>
      <description>&lt;p&gt;
I recently finished reading.
&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.amazon.com/gp/product/1590596528?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1590596528"&gt;&lt;img src="https://images-na.ssl-images-amazon.com/images/I/51v5h50rHaL._SL160_.jpg" border="0" /&gt;&lt;/a&gt;&lt;img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1590596528" width="1" border="0" /&gt; 
&lt;/td&gt;
&lt;td&gt;
&lt;a href="http://www.amazon.com/gp/product/1590596528?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1590596528"&gt;Deploying
.NET Applications: Learning MSBuild and ClickOnce (Expert's Voice in .Net)&lt;/a&gt;&lt;img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1590596528" width="1" border="0" /&gt; 
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
I was interested in this book mainly to find an easier way to deploy ClickOnce applications
via an automated build. Most of my build automation experience has been with Nant,
so I figured learning MSBuild couldn't hurt.
&lt;/p&gt;
&lt;p&gt;
This book targets the Visual Studio 2005 time frame, so some of the things that it
describes is out dated, mainly in regards to ClickCnce.
&lt;/p&gt;
&lt;p&gt;
There was a little coverage on mage.exe but not as much as I had liked. If you're
looking for a book to get you into the world of Clickonce or MSBuild, this one's pretty
good!
&lt;/p&gt;
&lt;p&gt;
Here are some of the things that I learned straight from the book. 
&lt;/p&gt;
&lt;h3&gt;MSBuild
&lt;/h3&gt;
&lt;p&gt;
Microsoft.Build.Framework and Microsoft.Build.Utilities contains some stuff to help
you with your builds. There's an ITask interface and a Task base class that you can
implement if you want to run some custom tasks from MSBuild.
&lt;/p&gt;
&lt;p&gt;
ClickOnce is driven by two XML-based manifest files called the deployment manifest
and the application manifest. 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Deployment manifest (.application) contains information specific to the deployment
of the system. 
&lt;/li&gt;
&lt;li&gt;
Application manifest (.manifest) captures information specific to version of the system. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;ClickOnce Deployment
&lt;/h3&gt;
&lt;p&gt;
The ClickOnce technology also has a programmatic interface that you can use to customize
deployment and updates. For example, if you have a plug-in where the core of the application
is deployed initially and then users are allowed to choose optional features (plug-ins)
and have them installed on demand, the ClickOnce API can help.
&lt;/p&gt;
&lt;p&gt;
ClickOnce applications have to be deployed to a Web server, to a file server, and/or
to removable media (such as CD/DVD). Moreover, you can deploy these applications in
one of two modes: offline or online.
&lt;/p&gt;
&lt;p&gt;
For applications that require finer-grained control over doing updates, application
authors can use the ClickOnce APIs to customize installation and updates.
&lt;/p&gt;
&lt;h3&gt;Code Access Security (CAS)
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
Permission: The authority to do something. 
&lt;/li&gt;
&lt;li&gt;
Permission set: A grouping of arbitrary permissions. 
&lt;/li&gt;
&lt;li&gt;
Origin based Evidence: Where your code comes from determines what permissions your
code gets. 
&lt;/li&gt;
&lt;li&gt;
Content base evidence: Your code content is signed and has a publisher certificate,
and that determines what permissions you get. 
&lt;/li&gt;
&lt;li&gt;
Code Group: Associates evidence with a permission set 
&lt;/li&gt;
&lt;li&gt;
Security Policy: Policies define a hierarchy of code groups. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;On-Demand Download
&lt;/h3&gt;
&lt;p&gt;
ClickOnce offers a facility that called on-demand download. The idea is that you create
groups of files and then use the ClickOnce APIs to download each group at runtime.
The initial download is reduced to what is needs to be downloaded to run the application,
and if a piece of functionality is not needed, it is not downloaded.
&lt;/p&gt;
&lt;p&gt;
You can get the path to the Data directory via:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div style="font-size: 14pt; background: black; color: white; font-family: consolas"&gt;
&lt;pre style="margin: 0px"&gt;&lt;span style="color: yellow"&gt;AppDomain&lt;/span&gt;.CurrentDomain.GetData(&lt;span style="color: lime"&gt;&amp;quot;DataDirectory&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="font-size: 14pt; background: black; color: white; font-family: consolas"&gt;
&lt;pre style="margin: 0px"&gt;&lt;span style="color: yellow"&gt;ApplicationDeployment&lt;/span&gt;.CurrentDeployment.DataDirectory;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="font-size: 14pt; background: black; color: white; font-family: consolas"&gt;
&lt;pre style="margin: 0px"&gt;&lt;span style="color: yellow"&gt;Application&lt;/span&gt;.LocalUserAppDataPath;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=98f944bb-8b1b-4e35-9a0e-e0502f27fe20" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=26fa1549-4418-4d84-9d10-bf1e6ecb21d4</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,26fa1549-4418-4d84-9d10-bf1e6ecb21d4.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently finished reading...
</p>
        <p>
        </p>
        <p>
          <a href="http://www.amazon.com/gp/product/0596523092?ie=UTF8&amp;tag=mokhthliofawa-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596523092">
            <img src="https://images-na.ssl-images-amazon.com/images/I/51psVmmlBZL._SL160_.jpg" border="0" />
          </a>
          <img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;l=as2&amp;o=1&amp;a=0596523092" width="1" border="0" />
        </p>
        <p>
          <a href="http://www.amazon.com/gp/product/0596523092?ie=UTF8&amp;tag=mokhthliofawa-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596523092">Data-Driven
Services with Silverlight 2</a>
          <img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;l=as2&amp;o=1&amp;a=0596523092" width="1" border="0" />
        </p>
        <p>
I have been wanting to get in to the world of WCF for some time now, but wasn't really
sure how to get started. This book was good at explaining how to get into WCF quick
and easy. The sample apps that the author goes through and provides are pretty cool
which makes it more fun.
</p>
        <p>
The book explains how data binding in silverlight (which seems to be similar to how
it works in WPF), how to pass objects across the wire using WCF. It explains what
RESTful services means, and how to build them leveraging tools on the .NET stack. 
</p>
        <p>
The sample apps include one that consumes Amazon's RESTful services, as well as a
Twitter client called SilverTwit. There's lots of code to dig through, and try out
for yourself.
</p>
        <p>
For anyone interesting in Silverlight or WCF, this is a good book to get you started.
</p>
        <p>
If you're looking for the <a href="http://examples.oreilly.com/9780596523091/">sample
code</a> that comes with the book, you can find it here. <a href="http://examples.oreilly.com/9780596523091/">http://examples.oreilly.com/9780596523091/</a></p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=26fa1549-4418-4d84-9d10-bf1e6ecb21d4" />
      </body>
      <title>Data-Driven Services with Silverlight 2</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,26fa1549-4418-4d84-9d10-bf1e6ecb21d4.aspx</guid>
      <link>http://mokhan.ca/blog/2009/03/11/DataDriven+Services+With+Silverlight+2.aspx</link>
      <pubDate>Wed, 11 Mar 2009 14:54:23 GMT</pubDate>
      <description>&lt;p&gt;
I recently finished reading...
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.amazon.com/gp/product/0596523092?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0596523092"&gt;&lt;img src="https://images-na.ssl-images-amazon.com/images/I/51psVmmlBZL._SL160_.jpg" border="0" /&gt;&lt;/a&gt;&lt;img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0596523092" width="1" border="0" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.amazon.com/gp/product/0596523092?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0596523092"&gt;Data-Driven
Services with Silverlight 2&lt;/a&gt;&lt;img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0596523092" width="1" border="0" /&gt;
&lt;/p&gt;
&lt;p&gt;
I have been wanting to get in to the world of WCF for some time now, but wasn't really
sure how to get started. This book was good at explaining how to get into WCF quick
and easy. The sample apps that the author goes through and provides are pretty cool
which makes it more fun.
&lt;/p&gt;
&lt;p&gt;
The book explains how data binding in silverlight (which seems to be similar to how
it works in WPF), how to pass objects across the wire using WCF. It explains what
RESTful services means, and how to build them leveraging tools on the .NET stack. 
&lt;/p&gt;
&lt;p&gt;
The sample apps include one that consumes Amazon's RESTful services, as well as a
Twitter client called SilverTwit. There's lots of code to dig through, and try out
for yourself.
&lt;/p&gt;
&lt;p&gt;
For anyone interesting in Silverlight or WCF, this is a good book to get you started.
&lt;/p&gt;
&lt;p&gt;
If you're looking for the &lt;a href="http://examples.oreilly.com/9780596523091/"&gt;sample
code&lt;/a&gt; that comes with the book, you can find it here. &lt;a href="http://examples.oreilly.com/9780596523091/"&gt;http://examples.oreilly.com/9780596523091/&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=26fa1549-4418-4d84-9d10-bf1e6ecb21d4" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=c042992e-7f01-4bf7-952d-7e89ecfbb499</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,c042992e-7f01-4bf7-952d-7e89ecfbb499.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently finished reading...
</p>
        <table>
          <tbody>
            <tr>
              <td>
                <p>
                  <a href="http://www.amazon.com/gp/product/1855383446?ie=UTF8&amp;tag=mokhthliofawa-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1855383446">
                    <img src="https://images-na.ssl-images-amazon.com/images/I/413DF0NHGYL._SL160_.jpg" border="0" />
                  </a>
                  <img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;l=as2&amp;o=1&amp;a=1855383446" width="1" border="0" />
                </p>
              </td>
              <td>
                <a href="http://www.amazon.com/gp/product/1855383446?ie=UTF8&amp;tag=mokhthliofawa-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1855383446">Introducing
NLP: Psychological Skills for Understanding and Influencing People</a>
                <img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;l=as2&amp;o=1&amp;a=1855383446" width="1" border="0" />
              </td>
            </tr>
          </tbody>
        </table>
        <p>
 
</p>
        <p>
I first heard about Neuro-linguistic programming (<a href="http://en.wikipedia.org/wiki/Neuro-linguistic_programming">NLP</a>)
while I was reading <a href="http://www.amazon.com/gp/product/0060554738?ie=UTF8&amp;tag=mokhthliofawa-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0060554738">The
Game: Penetrating the Secret Society of Pickup Artists</a><img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;l=as2&amp;o=1&amp;a=0060554738" width="1" border="0" />.
I thought that it sounded like an interesting subject, because I spend a good deal
of my time dealing with people and trying to learn new things. If you're interested
in trying to become a better communicator or you are interested in trying to find
out what your preferred way of learning is, this book will probably help!
</p>
        <p>
Below are some of the things that I learned straight from the book.
</p>
        <p>
The Four Stages of Learning
</p>
        <ol>
          <li>
Unconscious Incompetence 
</li>
          <li>
Conscious Incompetence 
</li>
          <li>
Conscious Competence 
</li>
          <li>
Unconscious Competence 
</li>
        </ol>
        <p>
If you always do what you've always done, you'll always get what you've got. If what
you are doing is not working, do something else.
</p>
        <p>
Communication is so much more than the words we say. These form only a small part
of our expressiveness as human beings. Research shows that in a presentation before
a group of people, 55 per cent of the impact is determined by your body language -
posture, gestures and eye contact - 38 per cent by your tone of voice, and only 7
per cent by the content of your presentation.
</p>
        <p>
We move our eyes in different directions in a systematic way depending on how we are
thinking. Neurological studies have shown that eye movement both laterally and vertically
seem to be associated with activating different parts of the brain.
</p>
        <p>
Movements and gestures will also tell you how a person is thinking. Many people will
point to the sense organ that they are using internally: they will point to their
ears while listening to sounds inside their head, point to the yes if visualizing,
or to the abdomen if they are feeling something strongly. These signs will not tell
you what a person is thinking about, only how he or she is thinking it. This is body
language at a much more refined and subtle level than it is normally interpreted.
</p>
        <p>
Beliefs can be a matter of choice. You can drop beliefs that limit you and build beliefs
that will make your life more fun and more successful. Positive beliefs allow you
to find out what could be true and how capable you are. They are permissions to explore
and play in the world of possibility.
</p>
        <p>
Towards people are energized by goals and rewards. Away people are motivated to avoid
problems and punishment. Arguing which is best in general is futile. 
</p>
        <p>
It is easy to recognize this pattern from a person's language. Does she talk about
what she wants, achieves or gains? Or does she tell you about the situation she wants
to avoid and the problems to steer clear of? Towards people are best employed in goal-getting.
Away from people are excellent at finding errors and work well in a job like quality
control. Art critics usually have a strong away orientation as many a performing artist
can testify!
</p>
        <blockquote>
          <p>
A good teacher will be able to create an environment, so her students learn for themselves
how to get the results.
</p>
        </blockquote>
        <p>
Learning to learn is the most important skill in education, and needs to be taught
from reception class onwards. The educational system concentrates mostly on what is
taught, the curriculum and omits the learning process. This has two consequences.
First, many students have difficulty picking up the information. Secondly, even if
they do learn it, it has little meaning for them, because it has been taken out of
context.
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=c042992e-7f01-4bf7-952d-7e89ecfbb499" />
      </body>
      <title>Introducing NLP</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,c042992e-7f01-4bf7-952d-7e89ecfbb499.aspx</guid>
      <link>http://mokhan.ca/blog/2009/03/02/Introducing+NLP.aspx</link>
      <pubDate>Mon, 02 Mar 2009 20:19:10 GMT</pubDate>
      <description>&lt;p&gt;
I recently finished reading...
&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;
&lt;a href="http://www.amazon.com/gp/product/1855383446?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1855383446"&gt;&lt;img src="https://images-na.ssl-images-amazon.com/images/I/413DF0NHGYL._SL160_.jpg" border="0" /&gt;&lt;/a&gt;&lt;img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1855383446" width="1" border="0" /&gt; 
&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;a href="http://www.amazon.com/gp/product/1855383446?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1855383446"&gt;Introducing
NLP: Psychological Skills for Understanding and Influencing People&lt;/a&gt;&lt;img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1855383446" width="1" border="0" /&gt; 
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
I first heard about Neuro-linguistic programming (&lt;a href="http://en.wikipedia.org/wiki/Neuro-linguistic_programming"&gt;NLP&lt;/a&gt;)
while I was reading &lt;a href="http://www.amazon.com/gp/product/0060554738?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0060554738"&gt;The
Game: Penetrating the Secret Society of Pickup Artists&lt;/a&gt;&lt;img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0060554738" width="1" border="0" /&gt;.
I thought that it sounded like an interesting subject, because I spend a good deal
of my time dealing with people and trying to learn new things. If you're interested
in trying to become a better communicator or you are interested in trying to find
out what your preferred way of learning is, this book will probably help!
&lt;/p&gt;
&lt;p&gt;
Below are some of the things that I learned straight from the book.
&lt;/p&gt;
&lt;p&gt;
The Four Stages of Learning
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Unconscious Incompetence 
&lt;/li&gt;
&lt;li&gt;
Conscious Incompetence 
&lt;/li&gt;
&lt;li&gt;
Conscious Competence 
&lt;/li&gt;
&lt;li&gt;
Unconscious Competence 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
If you always do what you've always done, you'll always get what you've got. If what
you are doing is not working, do something else.
&lt;/p&gt;
&lt;p&gt;
Communication is so much more than the words we say. These form only a small part
of our expressiveness as human beings. Research shows that in a presentation before
a group of people, 55 per cent of the impact is determined by your body language -
posture, gestures and eye contact - 38 per cent by your tone of voice, and only 7
per cent by the content of your presentation.
&lt;/p&gt;
&lt;p&gt;
We move our eyes in different directions in a systematic way depending on how we are
thinking. Neurological studies have shown that eye movement both laterally and vertically
seem to be associated with activating different parts of the brain.
&lt;/p&gt;
&lt;p&gt;
Movements and gestures will also tell you how a person is thinking. Many people will
point to the sense organ that they are using internally: they will point to their
ears while listening to sounds inside their head, point to the yes if visualizing,
or to the abdomen if they are feeling something strongly. These signs will not tell
you what a person is thinking about, only how he or she is thinking it. This is body
language at a much more refined and subtle level than it is normally interpreted.
&lt;/p&gt;
&lt;p&gt;
Beliefs can be a matter of choice. You can drop beliefs that limit you and build beliefs
that will make your life more fun and more successful. Positive beliefs allow you
to find out what could be true and how capable you are. They are permissions to explore
and play in the world of possibility.
&lt;/p&gt;
&lt;p&gt;
Towards people are energized by goals and rewards. Away people are motivated to avoid
problems and punishment. Arguing which is best in general is futile. 
&lt;/p&gt;
&lt;p&gt;
It is easy to recognize this pattern from a person's language. Does she talk about
what she wants, achieves or gains? Or does she tell you about the situation she wants
to avoid and the problems to steer clear of? Towards people are best employed in goal-getting.
Away from people are excellent at finding errors and work well in a job like quality
control. Art critics usually have a strong away orientation as many a performing artist
can testify!
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
A good teacher will be able to create an environment, so her students learn for themselves
how to get the results.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Learning to learn is the most important skill in education, and needs to be taught
from reception class onwards. The educational system concentrates mostly on what is
taught, the curriculum and omits the learning process. This has two consequences.
First, many students have difficulty picking up the information. Secondly, even if
they do learn it, it has little meaning for them, because it has been taken out of
context.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=c042992e-7f01-4bf7-952d-7e89ecfbb499" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=6211aec0-b801-474b-8270-5860ea27f704</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,6211aec0-b801-474b-8270-5860ea27f704.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently finished reading...
</p>
        <table width="100%">
          <tbody>
            <tr>
              <td>
                <p>
                  <a href="http://www.amazon.ca/gp/product/0735619654?ie=UTF8&amp;tag=mokhmypo-20&amp;linkCode=as2&amp;camp=15121&amp;creative=330641&amp;creativeASIN=0735619654">
                    <img src="https://images-na.ssl-images-amazon.com/images/I/516hULBjUmL._SL160_.jpg" border="0" />
                  </a>
                  <img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.ca/e/ir?t=mokhmypo-20&amp;l=as2&amp;o=15&amp;a=0735619654" width="1" border="0" />
                </p>
              </td>
              <td>
                <p>
                  <strong>Object Thinking</strong>
                  <em>by David West</em>
                </p>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
 
</p>
        <p>
As usual I fold down pages that contain paragraphs that interest me... below are a
few excerpts from the book that I enjoyed!
</p>
        <blockquote>
          <p>
"Better people" has been recognized as the most promising silver bullet
for addressing the software crisis, and yet almost all of our energy has been spent
on creating better tools, methods, and processes instead of better people?
</p>
        </blockquote>
        <p>
Imagine what a team of "better people" can accomplish. Now stop imaging,
and start investing in fostering cultures that cultivate "better people"
all working towards the same goal.
</p>
        <blockquote>
          <p>
An unspoken but just as widely held belief that really good developers were not to
be trusted - they could not be "managed", they all seemed to be "flaky"
to some degree, and they did not exhibit the loyalty to company and paycheck of "normal"
employees. Really "good" developers tended to be "artists", and
are was (is) not a good word in the context of software development.
</p>
        </blockquote>
        <p>
Those flaky artist types... *sigh* It's important to allow individuals do what they
are good at, that's obviously something they like to do. It breeds innovation, and
efficiency. When working in a team it's important to be respectful of one another's
opinions and work together. 
</p>
        <blockquote>
          <p>
Every once in a while someone on the team will have a crazy idea that just might slash
the complexity of the whole system. If they have courage, they'll try it out. It will
work (sometimes).
</p>
        </blockquote>
        <p>
It's important to have courage on any team. <a href="http://mokhan.ca/blog/2007/08/31/The+Principles+And+Values+Of+XP.aspx">XP
teams value courage</a>. Without the courage to grow and challenge one another, your
team will remain stagnant. By challenging one another you're showing one another respect
by saying that "I want you to get better, and I expect you to want me to get
better as well"!
</p>
        <blockquote>
          <p>
Object thinking is a "crazy idea" capable of increasing simplicity in software
design - crazy in the sense that it does not conform to traditional thinking about
software development, crazy in the sense that it revolts against the computer thinking
employed by most software developers, and crazy in many of the same ways that XP is
crazy.
</p>
        </blockquote>
        <p>
Trying to introduce object's into a culture that's firmly devoted to thinking in terms
of data can seem like a crazy idea too. There is a time and place for everything,
I'm sure objects aren't great for every system. A little bit of object "thinking"
can help though, I'm sure. 
</p>
        <blockquote>
          <p>
As a formalist, the computer scientist expects order and logic. The "goodness"
of a program is directly proportional to the degree to which it can be formally described
and formally manipulated. Proof - as in mathematical or logical proof - of correctness
for a piece of software is an ultimate objective. All that is bad in software arises
from deviations from formal descriptions that use precisely defined tokens and syntactic
rules. Art has no place in a program. In fact, many formalists would take the extreme
position: there is no such thing as art; art is nothing more than a formalism that
has yet to be discovered and explicated.
</p>
        </blockquote>
        <p>
Art is something that I enjoy. One of the reasons that I was drawn to software was
the creative aspects of it. I first thought of developing software as a form of art.
It's great how Test Driven Development allows you to prove the correctness of a piece
of software, but also enables you to refactor and be creative.
</p>
        <blockquote>
          <p>
An analogy to chess playing might illuminate the relationships among method categories.
A beginning chess player follows rules and defined procedures (they are formalists),
while a journeyman (informalist) relies on patterns and heuristics. A grandmaster
has internalized and transcended the informal to become an aformal player.
</p>
        </blockquote>
        <p>
I'm currently reading a book on <a href="http://en.wikipedia.org/wiki/Neuro-linguistic_programming">NLP</a>,
and it describes how experts do most of their work subconsciously, instead of consciously.
It's like when you learn to drive a car (assuming you learned on a manual transmission).
First you have a set of steps that you must follow, and repeat. Then you begin to
follow patterns. (I used to look at my current speed to decide whether to shift gears.)
Then you stop thinking about it, and you just drive.
</p>
        <blockquote>
          <p>
A human uses mechanical weights and machines in a gym to increase his innate capabilities
- to make his own muscles strong and more reliable. Using a more cerebral metaphor
(and one therefore more appropriate for object thinking), Kent Beck suggest using
method and even XP practices as if they were etudes (musical exercises designed to
help the musician internalize certain skills and techniques.)
</p>
        </blockquote>
        <p>
Time and Focus equates to discipline, according to me.  In order to excel at
something you need to invest both time and focus to truly excel at it. There really
is no secret to getting better.
</p>
        <blockquote>
          <p>
A common tendency for new object developers is to list as responsibilities things
that an object must "know." An airplane must "know its current location."
While this may be true, it can be misleading. It implies too much about how the object
might be implemented because "knows" implies an instance variable. It's
also quite possible that an object will know things (a private key for decryption,
perhaps) that it will not be willing to share with others and that therefore will
not be included in the interface for that object. <em>Provide private key </em>would
not appear as a service, although the message <em>privateKey</em> might be in the
object's protocol with the designation that it is a private message. <em>Decrypt message</em>,
on the other hand, might be a listed responsibility. Always state your responsibilities
in terms of a service, with an awareness of a possible client for that service.
</p>
        </blockquote>
        <p>
I know when I first started transitioning from procedural to object oriented programming,
I thought mostly about where and how the data was going to stored, and how to get
the data. "This auditor class needs to have a sorted list of audits"...
Now it's a little more like "An auditor can submit an audit of a company to ..."
</p>
        <p>
This was a great read for anyone wanting to get into objects, or learn more about
the history of objects. It was great to read about were a lot of present day ideas
originated from.
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=6211aec0-b801-474b-8270-5860ea27f704" />
      </body>
      <title>Object Thinking</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,6211aec0-b801-474b-8270-5860ea27f704.aspx</guid>
      <link>http://mokhan.ca/blog/2009/02/12/Object+Thinking.aspx</link>
      <pubDate>Thu, 12 Feb 2009 16:32:44 GMT</pubDate>
      <description>&lt;p&gt;
I recently finished reading...
&lt;/p&gt;
&lt;table width="100%"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;
&lt;a href="http://www.amazon.ca/gp/product/0735619654?ie=UTF8&amp;amp;tag=mokhmypo-20&amp;amp;linkCode=as2&amp;amp;camp=15121&amp;amp;creative=330641&amp;amp;creativeASIN=0735619654"&gt;&lt;img src="https://images-na.ssl-images-amazon.com/images/I/516hULBjUmL._SL160_.jpg" border="0" /&gt; &lt;/a&gt;&lt;img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.ca/e/ir?t=mokhmypo-20&amp;amp;l=as2&amp;amp;o=15&amp;amp;a=0735619654" width="1" border="0" /&gt; 
&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;
&lt;strong&gt;Object Thinking&lt;/strong&gt; &lt;em&gt;by David West&lt;/em&gt; 
&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
As usual I fold down pages that contain paragraphs that interest me... below are a
few excerpts from the book that I enjoyed!
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;Better people&amp;quot; has been recognized as the most promising silver bullet
for addressing the software crisis, and yet almost all of our energy has been spent
on creating better tools, methods, and processes instead of better people?
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Imagine what a team of &amp;quot;better people&amp;quot; can accomplish. Now stop imaging,
and start investing in fostering cultures that cultivate &amp;quot;better people&amp;quot;
all working towards the same goal.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
An unspoken but just as widely held belief that really good developers were not to
be trusted - they could not be &amp;quot;managed&amp;quot;, they all seemed to be &amp;quot;flaky&amp;quot;
to some degree, and they did not exhibit the loyalty to company and paycheck of &amp;quot;normal&amp;quot;
employees. Really &amp;quot;good&amp;quot; developers tended to be &amp;quot;artists&amp;quot;, and
are was (is) not a good word in the context of software development.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Those flaky artist types... *sigh* It's important to allow individuals do what they
are good at, that's obviously something they like to do. It breeds innovation, and
efficiency. When working in a team it's important to be respectful of one another's
opinions and work together. 
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Every once in a while someone on the team will have a crazy idea that just might slash
the complexity of the whole system. If they have courage, they'll try it out. It will
work (sometimes).
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
It's important to have courage on any team. &lt;a href="http://mokhan.ca/blog/2007/08/31/The+Principles+And+Values+Of+XP.aspx"&gt;XP
teams value courage&lt;/a&gt;. Without the courage to grow and challenge one another, your
team will remain stagnant. By challenging one another you're showing one another respect
by saying that &amp;quot;I want you to get better, and I expect you to want me to get
better as well&amp;quot;!
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Object thinking is a &amp;quot;crazy idea&amp;quot; capable of increasing simplicity in software
design - crazy in the sense that it does not conform to traditional thinking about
software development, crazy in the sense that it revolts against the computer thinking
employed by most software developers, and crazy in many of the same ways that XP is
crazy.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Trying to introduce object's into a culture that's firmly devoted to thinking in terms
of data can seem like a crazy idea too. There is a time and place for everything,
I'm sure objects aren't great for every system. A little bit of object &amp;quot;thinking&amp;quot;
can help though, I'm sure. 
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
As a formalist, the computer scientist expects order and logic. The &amp;quot;goodness&amp;quot;
of a program is directly proportional to the degree to which it can be formally described
and formally manipulated. Proof - as in mathematical or logical proof - of correctness
for a piece of software is an ultimate objective. All that is bad in software arises
from deviations from formal descriptions that use precisely defined tokens and syntactic
rules. Art has no place in a program. In fact, many formalists would take the extreme
position: there is no such thing as art; art is nothing more than a formalism that
has yet to be discovered and explicated.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Art is something that I enjoy. One of the reasons that I was drawn to software was
the creative aspects of it. I first thought of developing software as a form of art.
It's great how Test Driven Development allows you to prove the correctness of a piece
of software, but also enables you to refactor and be creative.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
An analogy to chess playing might illuminate the relationships among method categories.
A beginning chess player follows rules and defined procedures (they are formalists),
while a journeyman (informalist) relies on patterns and heuristics. A grandmaster
has internalized and transcended the informal to become an aformal player.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I'm currently reading a book on &lt;a href="http://en.wikipedia.org/wiki/Neuro-linguistic_programming"&gt;NLP&lt;/a&gt;,
and it describes how experts do most of their work subconsciously, instead of consciously.
It's like when you learn to drive a car (assuming you learned on a manual transmission).
First you have a set of steps that you must follow, and repeat. Then you begin to
follow patterns. (I used to look at my current speed to decide whether to shift gears.)
Then you stop thinking about it, and you just drive.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
A human uses mechanical weights and machines in a gym to increase his innate capabilities
- to make his own muscles strong and more reliable. Using a more cerebral metaphor
(and one therefore more appropriate for object thinking), Kent Beck suggest using
method and even XP practices as if they were etudes (musical exercises designed to
help the musician internalize certain skills and techniques.)
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Time and Focus equates to discipline, according to me.&amp;#160; In order to excel at
something you need to invest both time and focus to truly excel at it. There really
is no secret to getting better.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
A common tendency for new object developers is to list as responsibilities things
that an object must &amp;quot;know.&amp;quot; An airplane must &amp;quot;know its current location.&amp;quot;
While this may be true, it can be misleading. It implies too much about how the object
might be implemented because &amp;quot;knows&amp;quot; implies an instance variable. It's
also quite possible that an object will know things (a private key for decryption,
perhaps) that it will not be willing to share with others and that therefore will
not be included in the interface for that object. &lt;em&gt;Provide private key &lt;/em&gt;would
not appear as a service, although the message &lt;em&gt;privateKey&lt;/em&gt; might be in the
object's protocol with the designation that it is a private message. &lt;em&gt;Decrypt message&lt;/em&gt;,
on the other hand, might be a listed responsibility. Always state your responsibilities
in terms of a service, with an awareness of a possible client for that service.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I know when I first started transitioning from procedural to object oriented programming,
I thought mostly about where and how the data was going to stored, and how to get
the data. &amp;quot;This auditor class needs to have a sorted list of audits&amp;quot;...
Now it's a little more like &amp;quot;An auditor can submit an audit of a company to ...&amp;quot;
&lt;/p&gt;
&lt;p&gt;
This was a great read for anyone wanting to get into objects, or learn more about
the history of objects. It was great to read about were a lot of present day ideas
originated from.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=6211aec0-b801-474b-8270-5860ea27f704" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=cec97d20-f246-4fd7-911e-b473142cfe8d</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,cec97d20-f246-4fd7-911e-b473142cfe8d.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I finished reading...
</p>
        <table border="0">
          <tbody>
            <tr>
              <td valign="top">
                <a href="http://www.amazon.com/Principles-Patterns-Practices-Robert-Martin/dp/0131857258%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0131857258">
                  <img src="http://ecx.images-amazon.com/images/I/51Y57BH27TL._SL75_.jpg" border="1" />
                </a>
              </td>
              <td valign="top">
                <b>Agile Principles, Patterns, and Practices in C# (Robert C. Martin Series)</b>
                <br />
by Robert C. Martin, Micah Martin 
<br /><br /><a href="http://www.amazon.com/Principles-Patterns-Practices-Robert-Martin/dp/0131857258%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0131857258">Read
more about this book...</a></td>
            </tr>
          </tbody>
        </table>
        <p>
 
</p>
        <p>
What an excellent book, seriously! It was written by <a href="http://www.objectmentor.com/omTeam/martin_r.html">Robert
C. Martin</a> and his son Micah. The following is a list of excerpts from the book
that I can appreciate:
</p>
        <p>
"Continuous attention to technical excellence and good design enhances agility.
High quality is the key to high speed. The way to go fast is to keep the software
as clean and robust as possible. Thus, all agile team members are committed to producing
only the highest quality code they can. They do not make messes and then tell themselves
that they'll clean up when they have more time. They clean any messes as they are
made."
</p>
        <p>
"The goal of refactoring, as depicted in this chapter, is to clean your code
every day, every hour and every minute. We don't want the mess to build. We don't
want to have to chisel and scrub the encrusted bits that accumulate over time. We
want to be able to extend and modify our systems with a minimum of effort. The most
important enabler of that ability is the cleanliness of code."
</p>
        <p>
"<strong>Specifying contracts in unit tests.</strong> Contracts can also be specified
by writing unit tests. By thoroughly testing the behavior of a class, the unit tests
make the behavior of the class clear. Authors of client code will want to review the
unit tests in order to know what to reasonably assume about the classes they are using."
</p>
        <p>
"Databases are implementation details! Consideration of the database should be
deferred as long as possible. Far too many applications were designed with the database
in mind from the beginning and so are inextricably tied to those databases. Remember
the definition of abstraction: <em>"the amplification of the essential and the
elimination of the irrelevant."</em> At this stage of the project, the database
is irrelevant; it is merely a technique used for storing and accessing data, nothing
more."
</p>
        <p>
"This style of testing is called behavior-driven development. The idea is that
you should not think of tests as tests, where you make assertions about state and
results. Instead, you should think of tests as <em>specifications of behavior</em>,
in which you describe how the code is supposed to behave."
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=cec97d20-f246-4fd7-911e-b473142cfe8d" />
      </body>
      <title>Disciplined Agility</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,cec97d20-f246-4fd7-911e-b473142cfe8d.aspx</guid>
      <link>http://mokhan.ca/blog/2008/08/09/Disciplined+Agility.aspx</link>
      <pubDate>Sat, 09 Aug 2008 17:01:28 GMT</pubDate>
      <description>&lt;p&gt;
I finished reading...
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;a href="http://www.amazon.com/Principles-Patterns-Practices-Robert-Martin/dp/0131857258%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0131857258"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/51Y57BH27TL._SL75_.jpg" border="1" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Agile Principles, Patterns, and Practices in C# (Robert C. Martin Series)&lt;/b&gt; 
&lt;br /&gt;
by Robert C. Martin, Micah Martin 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/Principles-Patterns-Practices-Robert-Martin/dp/0131857258%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0131857258"&gt;Read
more about this book...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
What an excellent book, seriously! It was written by &lt;a href="http://www.objectmentor.com/omTeam/martin_r.html"&gt;Robert
C. Martin&lt;/a&gt; and his son Micah. The following is a list of excerpts from the book
that I can appreciate:
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Continuous attention to technical excellence and good design enhances agility.
High quality is the key to high speed. The way to go fast is to keep the software
as clean and robust as possible. Thus, all agile team members are committed to producing
only the highest quality code they can. They do not make messes and then tell themselves
that they'll clean up when they have more time. They clean any messes as they are
made.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;The goal of refactoring, as depicted in this chapter, is to clean your code
every day, every hour and every minute. We don't want the mess to build. We don't
want to have to chisel and scrub the encrusted bits that accumulate over time. We
want to be able to extend and modify our systems with a minimum of effort. The most
important enabler of that ability is the cleanliness of code.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;&lt;strong&gt;Specifying contracts in unit tests.&lt;/strong&gt; Contracts can also be specified
by writing unit tests. By thoroughly testing the behavior of a class, the unit tests
make the behavior of the class clear. Authors of client code will want to review the
unit tests in order to know what to reasonably assume about the classes they are using.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Databases are implementation details! Consideration of the database should be
deferred as long as possible. Far too many applications were designed with the database
in mind from the beginning and so are inextricably tied to those databases. Remember
the definition of abstraction: &lt;em&gt;&amp;quot;the amplification of the essential and the
elimination of the irrelevant.&amp;quot;&lt;/em&gt; At this stage of the project, the database
is irrelevant; it is merely a technique used for storing and accessing data, nothing
more.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;This style of testing is called behavior-driven development. The idea is that
you should not think of tests as tests, where you make assertions about state and
results. Instead, you should think of tests as &lt;em&gt;specifications of behavior&lt;/em&gt;,
in which you describe how the code is supposed to behave.&amp;quot;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=cec97d20-f246-4fd7-911e-b473142cfe8d" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=b3ffc8bb-af83-430a-8ebf-a8b1f5da05a6</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,b3ffc8bb-af83-430a-8ebf-a8b1f5da05a6.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In case you haven't you should read...
</p>
        <table border="0">
          <tbody>
            <tr>
              <td valign="top">
                <a href="http://www.amazon.com/xUnit-Test-Patterns-Refactoring-Addison-Wesley/dp/0131495054%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0131495054">
                  <img src="http://ecx.images-amazon.com/images/I/51ZfuTVoX0L._SL75_.jpg" border="1" />
                </a>
              </td>
              <td valign="top">
                <b>xUnit Test Patterns: Refactoring Test Code (The Addison-Wesley Signature Series)</b>
                <br />
by Gerard Meszaros 
<br /><br /><a href="http://www.amazon.com/xUnit-Test-Patterns-Refactoring-Addison-Wesley/dp/0131495054%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0131495054">Read
more about this book...</a></td>
            </tr>
          </tbody>
        </table>
        <p>
 
</p>
        <p>
As a reminder, let's talk about a test smell described in the above mentioned book.
It's called "Conditional Test Logic".
</p>
        <blockquote>
          <p>
            <strong>"Conditional Test Logic:</strong> A test contains code that may or may
not be executed." xUnit Test Patterns
</p>
        </blockquote>
        <p>
"A fully automated test is just code that verifies the behavior or other code.
But if this code is complicated, how do we verify that it works properly?"
</p>
        <p>
Warning bells should sound off in your head when you start to see looping or conditional
constructs within a single unit test.
</p>
        <p>
"Code that has only a single execution path always executes in exactly the same
way. Code that has multiple execution paths presents much greater challenges and does
not inspire as much confidence about its outcome."
</p>
        <p>
For more information check <a href="http://xunitpatterns.com/Conditional%20Test%20Logic.html">this
out...</a></p>
        <p>
B<a href="http://weblogs.asp.net/bsimser/archive/2008/06/27/testing-castle-windsor-mappings-part-deux.aspx"></a>asically
Ignore Logic... that could cause multiple execution paths within a single unit test.
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b3ffc8bb-af83-430a-8ebf-a8b1f5da05a6" />
      </body>
      <title>Holy Conditionals Batman...</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,b3ffc8bb-af83-430a-8ebf-a8b1f5da05a6.aspx</guid>
      <link>http://mokhan.ca/blog/2008/07/10/Holy+Conditionals+Batman.aspx</link>
      <pubDate>Thu, 10 Jul 2008 02:17:32 GMT</pubDate>
      <description>&lt;p&gt;
In case you haven't you should read...
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;a href="http://www.amazon.com/xUnit-Test-Patterns-Refactoring-Addison-Wesley/dp/0131495054%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0131495054"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/51ZfuTVoX0L._SL75_.jpg" border="1" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;xUnit Test Patterns: Refactoring Test Code (The Addison-Wesley Signature Series)&lt;/b&gt; 
&lt;br /&gt;
by Gerard Meszaros 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/xUnit-Test-Patterns-Refactoring-Addison-Wesley/dp/0131495054%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0131495054"&gt;Read
more about this book...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
As a reminder, let's talk about a test smell described in the above mentioned book.
It's called &amp;quot;Conditional Test Logic&amp;quot;.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;strong&gt;&amp;quot;Conditional Test Logic:&lt;/strong&gt; A test contains code that may or may
not be executed.&amp;quot; xUnit Test Patterns
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;quot;A fully automated test is just code that verifies the behavior or other code.
But if this code is complicated, how do we verify that it works properly?&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Warning bells should sound off in your head when you start to see looping or conditional
constructs within a single unit test.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Code that has only a single execution path always executes in exactly the same
way. Code that has multiple execution paths presents much greater challenges and does
not inspire as much confidence about its outcome.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
For more information check &lt;a href="http://xunitpatterns.com/Conditional%20Test%20Logic.html"&gt;this
out...&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
B&lt;a href="http://weblogs.asp.net/bsimser/archive/2008/06/27/testing-castle-windsor-mappings-part-deux.aspx"&gt;&lt;/a&gt;asically
Ignore Logic... that could cause multiple execution paths within a single unit test.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b3ffc8bb-af83-430a-8ebf-a8b1f5da05a6" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
      <category>TDD</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=216e16e5-5885-4d1c-a652-80ea47011279</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,216e16e5-5885-4d1c-a652-80ea47011279.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tonight I finished reading...
</p>
        <table border="0">
          <tbody>
            <tr>
              <td valign="top">
                <a href="http://www.amazon.com/C-Depth-What-need-master/dp/1933988363%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1933988363">
                  <img src="http://ecx.images-amazon.com/images/I/41oFdTsrz9L._SL75_.jpg" border="1" />
                </a>
              </td>
              <td valign="top">
                <b>C# in Depth: What you need to master C# 2 and 3</b>
                <br />
by Jon Skeet 
<br /><br /><a href="http://www.amazon.com/C-Depth-What-need-master/dp/1933988363%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1933988363">Read
more about this book...</a></td>
            </tr>
          </tbody>
        </table>
        <p>
This was an amazing book, and definitely offers a great <strong>in depth</strong> look
at the C# language. Most importantly it answered a lot of my questions about elements
introduced in C# 3.0, and taught me things I didn't know about C# 1.0. If you're looking
for information on the following items, then this book is definitely for you.
</p>
        <ul>
          <li>
Expression 
</li>
          <li>
IQueryable 
</li>
          <li>
IQueryProvider 
</li>
          <li>
Lamba's 
</li>
          <li>
Type Inferencing 
</li>
        </ul>
        <p>
          <a href="www.jpboodhoo.com/blog/BookReviewCInDepth.aspx">Thanks JP for recommending
this book!</a>
        </p>
        <p>
Here are a few gems that I picked from this book.
</p>
        <h3>Delegates
</h3>
        <p>
"You rarely see an explicit call to Delegate.Combine in C# code - usually the
+ and += operators are used."
</p>
        <pre class="code">
          <span style="color: blue">var </span>x = <span style="color: blue">new </span><span style="color: #2b91af">EventHandler</span>(<span style="color: blue">delegate </span>{
}); <span style="color: blue">var </span>y = <span style="color: blue">new </span><span style="color: #2b91af">EventHandler</span>(<span style="color: blue">delegate </span>{
}); x += y; x = x + y;<span style="color: green">// same as above </span>x = (<span style="color: #2b91af">EventHandler</span>) <span style="color: #2b91af">Delegate</span>.Combine(x,
y);<span style="color: green">// same as above</span></pre>
        <h3>Static vs Dynamic Typing
</h3>
        <p>
"C# is statically typed: each variable is of a particular type, and that type
is known at compile time. The alternate to static typing is dynamic typing, which
can take a variety of guises. "
</p>
        <h3>Explicit vs. Implicit Typing
</h3>
        <p>
"The distinction between explicit typing and implicit typing is only relevant
in statically typed languages. With explicitly typing, the type of every variable
must be explicitly stated in the declaration. Implicit typing allows the compiler
to infer the type of the variable based on its use."
</p>
        <h3>Covariant vs. Incovariant
</h3>
        <pre class="code">
          <span style="color: blue">object</span>[] stuff = <span style="color: blue">new
string</span>[]{<span style="color: #a31515">"blah"</span>}; <span style="color: green">//
valid and is an example of covariance </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">object</span>&gt;
more_stuff = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;();<span style="color: green">//
invalid and is an example of incovariance</span></pre>
        <pre class="code">
          <span style="color: green">
          </span>
        </pre>
        <h3>Fluent Interfaces
</h3>
        <p>
Jon, the author, mentions a blog post by Anders Noras on <a href="http://andersnoras.com/blogs/anoras/archive/2007/07/09/behind-the-scenes-of-the-planning-dsl.aspx">Planning
a fluent interface</a></p>
        <p>
Here's an example of a fluent interface for building menu's that I've been playing
with.
</p>
        <pre class="code">CreateA.MenuItem()
.Named(<span style="color: #a31515">"&amp;Close"</span>)
.BelongsTo(<span style="color: #2b91af">MenuGroups</span>.File) .CanBeClickedWhen(m
=&gt; task.IsThereAProtocolSelected()) .WhenClickedExecute(closeCommand) .Build();</pre>
        <h3>Readability
</h3>
        <p>
"When it comes to getting the broad sweep of code, what is required is 'readability
of results' - I want to know what the code does, but I don't care how it does it right
now."
</p>
        <p>
There's a lot of information on IQueryables, Expression Trees, and other goodness
in this book. This is a great book and definitely worth reading, especially if you're
as interested in the C# language as I am.
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=216e16e5-5885-4d1c-a652-80ea47011279" />
      </body>
      <title>In Depth With C#</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,216e16e5-5885-4d1c-a652-80ea47011279.aspx</guid>
      <link>http://mokhan.ca/blog/2008/07/07/In+Depth+With+C.aspx</link>
      <pubDate>Mon, 07 Jul 2008 02:45:12 GMT</pubDate>
      <description>&lt;p&gt;
Tonight I finished reading...
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;a href="http://www.amazon.com/C-Depth-What-need-master/dp/1933988363%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1933988363"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/41oFdTsrz9L._SL75_.jpg" border="1" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;C# in Depth: What you need to master C# 2 and 3&lt;/b&gt; 
&lt;br /&gt;
by Jon Skeet 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/C-Depth-What-need-master/dp/1933988363%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1933988363"&gt;Read
more about this book...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
This was an amazing book, and definitely offers a great &lt;strong&gt;in depth&lt;/strong&gt; look
at the C# language. Most importantly it answered a lot of my questions about elements
introduced in C# 3.0, and taught me things I didn't know about C# 1.0. If you're looking
for information on the following items, then this book is definitely for you.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Expression 
&lt;/li&gt;
&lt;li&gt;
IQueryable 
&lt;/li&gt;
&lt;li&gt;
IQueryProvider 
&lt;/li&gt;
&lt;li&gt;
Lamba's 
&lt;/li&gt;
&lt;li&gt;
Type Inferencing 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a href="www.jpboodhoo.com/blog/BookReviewCInDepth.aspx"&gt;Thanks JP for recommending
this book!&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Here are a few gems that I picked from this book.
&lt;/p&gt;
&lt;h3&gt;Delegates
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;You rarely see an explicit call to Delegate.Combine in C# code - usually the
+ and += operators are used.&amp;quot;
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;x = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EventHandler&lt;/span&gt;(&lt;span style="color: blue"&gt;delegate &lt;/span&gt;{
}); &lt;span style="color: blue"&gt;var &lt;/span&gt;y = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EventHandler&lt;/span&gt;(&lt;span style="color: blue"&gt;delegate &lt;/span&gt;{
}); x += y; x = x + y;&lt;span style="color: green"&gt;// same as above &lt;/span&gt;x = (&lt;span style="color: #2b91af"&gt;EventHandler&lt;/span&gt;) &lt;span style="color: #2b91af"&gt;Delegate&lt;/span&gt;.Combine(x,
y);&lt;span style="color: green"&gt;// same as above&lt;/span&gt;&lt;/pre&gt;
&lt;h3&gt;Static vs Dynamic Typing
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;C# is statically typed: each variable is of a particular type, and that type
is known at compile time. The alternate to static typing is dynamic typing, which
can take a variety of guises. &amp;quot;
&lt;/p&gt;
&lt;h3&gt;Explicit vs. Implicit Typing
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;The distinction between explicit typing and implicit typing is only relevant
in statically typed languages. With explicitly typing, the type of every variable
must be explicitly stated in the declaration. Implicit typing allows the compiler
to infer the type of the variable based on its use.&amp;quot;
&lt;/p&gt;
&lt;h3&gt;Covariant vs. Incovariant
&lt;/h3&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;object&lt;/span&gt;[] stuff = &lt;span style="color: blue"&gt;new
string&lt;/span&gt;[]{&lt;span style="color: #a31515"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;}; &lt;span style="color: green"&gt;//
valid and is an example of covariance &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;object&lt;/span&gt;&amp;gt;
more_stuff = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;();&lt;span style="color: green"&gt;//
invalid and is an example of incovariance&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: green"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h3&gt;Fluent Interfaces
&lt;/h3&gt;
&lt;p&gt;
Jon, the author, mentions a blog post by Anders Noras on &lt;a href="http://andersnoras.com/blogs/anoras/archive/2007/07/09/behind-the-scenes-of-the-planning-dsl.aspx"&gt;Planning
a fluent interface&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Here's an example of a fluent interface for building menu's that I've been playing
with.
&lt;/p&gt;
&lt;pre class="code"&gt;CreateA.MenuItem()
.Named(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;amp;Close&amp;quot;&lt;/span&gt;)
.BelongsTo(&lt;span style="color: #2b91af"&gt;MenuGroups&lt;/span&gt;.File) .CanBeClickedWhen(m
=&amp;gt; task.IsThereAProtocolSelected()) .WhenClickedExecute(closeCommand) .Build();&lt;/pre&gt;
&lt;h3&gt;Readability
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;When it comes to getting the broad sweep of code, what is required is 'readability
of results' - I want to know what the code does, but I don't care how it does it right
now.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
There's a lot of information on IQueryables, Expression Trees, and other goodness
in this book. This is a great book and definitely worth reading, especially if you're
as interested in the C# language as I am.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=216e16e5-5885-4d1c-a652-80ea47011279" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=0ebf648d-419f-4f35-bc83-968dcb58220b</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,0ebf648d-419f-4f35-bc83-968dcb58220b.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last week I finished reading...
</p>
        <table border="0">
          <tbody>
            <tr>
              <td valign="top">
                <a href="http://www.amazon.com/Habits-Highly-Effective-People/dp/0743269519%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0743269519">
                  <img src="http://ecx.images-amazon.com/images/I/51WQECVJG4L._SL75_.jpg" border="1" />
                </a>
              </td>
              <td valign="top">
                <b>The 7 Habits of Highly Effective People</b>
                <br />
by Stephen R. Covey 
<br /><br /><a href="http://www.amazon.com/Habits-Highly-Effective-People/dp/0743269519%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0743269519">Read
more about this book...</a></td>
            </tr>
          </tbody>
        </table>
        <p>
I really enjoyed this book, it's definitely worth taking the time to sit down and
read. I realized a lot about myself as I read it. Hopefully you will too! Here are
a few excerpts from the book that had an impact on me.
</p>
        <p>
"Management is a bottom line focus: How can I best accomplish certain things?
Leadership deals with the top line: What are the things I want to accomplish?"
</p>
        <p>
"... envision a group of producers cutting their way through the jungle with
machetes. They're the producers, the problem solvers. They're cutting through the
undergrowth, clearing it out.
</p>
        <p>
The managers are behind them, sharpening their machetes, writing policy and procedure
manuals, holding muscle development programs, bringing in improved technologies and
setting up working schedules and compensation programs for machete wielders.
</p>
        <p>
The leader is the one who climbs the tallest tree, surveys the entire situation, and
yells, 'Wrong Jungle!'"
</p>
        <p>
"Work Centeredness. Work-centered people may become 'workaholics,' driving themselves
to produce at the sacrifice of health, relationships, and other important areas of
their lives. Their fundamental identity comes from their work - 'I'm a doctor', 'I'm
a writer', 'I'm an actor.'
</p>
        <p>
Because their identity and sense of self-worth are wrapped up in their work, their
security is vulnerable to anything that happens to prevent them from continuing in
it. Their guidance is a function of the demands of the work. Their wisdom and power
come in the limited areas of their work, rendering them ineffective in other areas
of life."
</p>
        <p>
"There are times when neither the teacher nor the student knows for sure what's
going to happen. In the beginning, there's a safe environment that enables people
to be really open and to learn and to listen to each other's ideas. Then comes brainstorming,
where the spirit of evaluation is subordinated to the spirit of creativity, imagining,
and intellectual networking. Then an absolutely unusual phenomenon begins to take
place. The entire class is transformed with the excitement of a new thrust, a new
idea, a new direction that's hard to define, yet it's almost palpable to the people
involved."
</p>
        <blockquote>
          <p>
"Suppose you were to come upon someone in the woods working feverishly to saw
down a tree. 
</p>
          <p>
'What are you doing?' you ask. 
</p>
          <p>
'Can't you see?' comes the impatient reply. 'I'm sawing down this tree.' 
</p>
          <p>
'You look exhausted!' you exclaim. 'How long have you been at it?' 
</p>
          <p>
'Over five hours,' he returns, 'and I'm beat! This is hard work.'
</p>
          <p>
'Well, why don't you take a break for a few minutes and sharpen that saw?' you inquire.
'I'm sure it would go a lot faster.'
</p>
          <p>
'I don't have time to sharpen the saw,' then man says emphatically. 'I'm too busy
sawing!'"
</p>
        </blockquote>
        <p>
"Principles are natural laws that are external to us and that ultimately control
the consequences of our actions. Values are internal and subjective and represent
that which we feel strongest about in guiding our behavior."
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=0ebf648d-419f-4f35-bc83-968dcb58220b" />
      </body>
      <title>Trying to be more effective</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,0ebf648d-419f-4f35-bc83-968dcb58220b.aspx</guid>
      <link>http://mokhan.ca/blog/2008/07/07/Trying+To+Be+More+Effective.aspx</link>
      <pubDate>Mon, 07 Jul 2008 01:50:38 GMT</pubDate>
      <description>&lt;p&gt;
Last week I finished reading...
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;a href="http://www.amazon.com/Habits-Highly-Effective-People/dp/0743269519%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0743269519"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/51WQECVJG4L._SL75_.jpg" border="1" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;The 7 Habits of Highly Effective People&lt;/b&gt; 
&lt;br /&gt;
by Stephen R. Covey 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/Habits-Highly-Effective-People/dp/0743269519%3FSubscriptionId%3D0525E2PQ81DD7ZTWTK82%26tag%3Dws%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0743269519"&gt;Read
more about this book...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
I really enjoyed this book, it's definitely worth taking the time to sit down and
read. I realized a lot about myself as I read it. Hopefully you will too! Here are
a few excerpts from the book that had an impact on me.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Management is a bottom line focus: How can I best accomplish certain things?
Leadership deals with the top line: What are the things I want to accomplish?&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;... envision a group of producers cutting their way through the jungle with
machetes. They're the producers, the problem solvers. They're cutting through the
undergrowth, clearing it out.
&lt;/p&gt;
&lt;p&gt;
The managers are behind them, sharpening their machetes, writing policy and procedure
manuals, holding muscle development programs, bringing in improved technologies and
setting up working schedules and compensation programs for machete wielders.
&lt;/p&gt;
&lt;p&gt;
The leader is the one who climbs the tallest tree, surveys the entire situation, and
yells, 'Wrong Jungle!'&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Work Centeredness. Work-centered people may become 'workaholics,' driving themselves
to produce at the sacrifice of health, relationships, and other important areas of
their lives. Their fundamental identity comes from their work - 'I'm a doctor', 'I'm
a writer', 'I'm an actor.'
&lt;/p&gt;
&lt;p&gt;
Because their identity and sense of self-worth are wrapped up in their work, their
security is vulnerable to anything that happens to prevent them from continuing in
it. Their guidance is a function of the demands of the work. Their wisdom and power
come in the limited areas of their work, rendering them ineffective in other areas
of life.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;There are times when neither the teacher nor the student knows for sure what's
going to happen. In the beginning, there's a safe environment that enables people
to be really open and to learn and to listen to each other's ideas. Then comes brainstorming,
where the spirit of evaluation is subordinated to the spirit of creativity, imagining,
and intellectual networking. Then an absolutely unusual phenomenon begins to take
place. The entire class is transformed with the excitement of a new thrust, a new
idea, a new direction that's hard to define, yet it's almost palpable to the people
involved.&amp;quot;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;Suppose you were to come upon someone in the woods working feverishly to saw
down a tree. 
&lt;/p&gt;
&lt;p&gt;
'What are you doing?' you ask. 
&lt;/p&gt;
&lt;p&gt;
'Can't you see?' comes the impatient reply. 'I'm sawing down this tree.' 
&lt;/p&gt;
&lt;p&gt;
'You look exhausted!' you exclaim. 'How long have you been at it?' 
&lt;/p&gt;
&lt;p&gt;
'Over five hours,' he returns, 'and I'm beat! This is hard work.'
&lt;/p&gt;
&lt;p&gt;
'Well, why don't you take a break for a few minutes and sharpen that saw?' you inquire.
'I'm sure it would go a lot faster.'
&lt;/p&gt;
&lt;p&gt;
'I don't have time to sharpen the saw,' then man says emphatically. 'I'm too busy
sawing!'&amp;quot;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;quot;Principles are natural laws that are external to us and that ultimately control
the consequences of our actions. Values are internal and subjective and represent
that which we feel strongest about in guiding our behavior.&amp;quot;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=0ebf648d-419f-4f35-bc83-968dcb58220b" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=9e6decbc-9160-4ecc-a334-ed1712fa9ff9</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,9e6decbc-9160-4ecc-a334-ed1712fa9ff9.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm currently reading... 
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/51WQECVJG4L._SL75_.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>The 7 Habits of Highly Effective People</b>
                  <br />
by Stephen R. Covey 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0743269519%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Habits-Highly-Effective-People/dp/0743269519%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
I came across a paragraph that stuck out for me, and just wanted to share it:
</p>
        <p>
"If you don't let a teacher know at what level you are -- by asking a questions,
or revealing your ignorance - you will not learn or grow. You cannot pretend for long,
for you will eventually be found out. Admission of ignorance is often the first step
in our education."
</p>
        <p>
This was immediately followed by the next powerful statement.
</p>
        <p>
"Thoreau taught, <strong>'How can we remember our ignorance, which our growth
requires, when we are using our knowledge all the time?'</strong>"
</p>
        <p>
Note to self, "be more ignorant..." *giggle* Have a great day!
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=9e6decbc-9160-4ecc-a334-ed1712fa9ff9" />
      </body>
      <title>Effective People</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,9e6decbc-9160-4ecc-a334-ed1712fa9ff9.aspx</guid>
      <link>http://mokhan.ca/blog/2008/06/19/Effective+People.aspx</link>
      <pubDate>Thu, 19 Jun 2008 12:07:35 GMT</pubDate>
      <description>&lt;p&gt;
I'm currently reading... 
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/51WQECVJG4L._SL75_.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;The 7 Habits of Highly Effective People&lt;/b&gt; 
&lt;br /&gt;
by Stephen R. Covey 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0743269519%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Habits-Highly-Effective-People/dp/0743269519%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
I came across a paragraph that stuck out for me, and just wanted to share it:
&lt;/p&gt;
&lt;p&gt;
&amp;quot;If you don't let a teacher know at what level you are -- by asking a questions,
or revealing your ignorance - you will not learn or grow. You cannot pretend for long,
for you will eventually be found out. Admission of ignorance is often the first step
in our education.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
This was immediately followed by the next powerful statement.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Thoreau taught, &lt;strong&gt;'How can we remember our ignorance, which our growth
requires, when we are using our knowledge all the time?'&lt;/strong&gt;&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Note to self, &amp;quot;be more ignorant...&amp;quot; *giggle* Have a great day!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=9e6decbc-9160-4ecc-a334-ed1712fa9ff9" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=b10867fd-061a-48a0-9ff5-a2f72947f5a3</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,b10867fd-061a-48a0-9ff5-a2f72947f5a3.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm currently reading...
</p>
        <table border="0">
          <tbody>
            <tr>
              <td valign="top">
                <a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131489062%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Applying-UML-Patterns-Introduction-Object-Oriented/dp/0131489062%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">
                  <img src="http://ecx.images-amazon.com/images/I/51aukquzeFL._SL75_.jpg" border="1" />
                </a>
              </td>
              <td valign="top">
                <b>Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design
and Iterative Development (3rd Edition)</b>
                <br />
by Craig Larman 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131489062%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Applying-UML-Patterns-Introduction-Object-Oriented/dp/0131489062%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this book...</a></td>
            </tr>
          </tbody>
        </table>
        <p>
(I'm actually reading the 2nd edition)
</p>
        <p>
This is a good book. It started off really boring... really boring! I picked up this
book as an introduction to object oriented programming, and it started off with a
lot of talk on UML, documentation and the Rational Unified Process. But then I got
to chapter 16... "GRASP: Designing Objects with Responsibilities".
</p>
        <p>
Here's an excerpt that I enjoyed!
</p>
        <p>
"Perhaps the most common mistake when creating a domain model is to represent
something as an attribute when it should have been a concept. A rule of thumb to help
prevent this mistake is:
</p>
        <p>
          <strong>If we do not think of some conceptual class X as a number or text in the real
world, X is probably a conceptual class, not an attribute</strong>."
</p>
        <p>
Here's a definition for a Domain Model...
</p>
        <p>
"The Domain Model provides a visual dictionary of the domain vocabulary and concepts
from which to draw inspiration for the naming of some things in the software design."
</p>
        <p>
Chapter 16 is great so far, it talks about how to decompose responsibilities for objects
using an acronym (I'm not a fan of acronyms) called GRASP. GRASP stands for General
Responsibility Assignment Software Patterns. 
</p>
        <p>
Craig goes on to talk about the five different patterns of GRASP. They are:
</p>
        <ul>
          <li>
            <strong>Information Expert</strong>: the class that has the information necessary
to fulfill the responsibility.</li>
          <li>
            <strong>Creator</strong>: a class that has the responsibility to create an instance
of another class.</li>
          <li>
            <strong>High Cohesion</strong>: increase the measure of how strongly related and focused
the responsibilities of an element are.</li>
          <li>
            <strong>Low Coupling</strong>: decrease the amount a class is connected to, has knowledge
of, or relies on other elements.</li>
          <li>
            <strong>Controller:</strong> a class with the responsibility of receiving or handling
a system event message.</li>
        </ul>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b10867fd-061a-48a0-9ff5-a2f72947f5a3" />
      </body>
      <title>Studying Object Oriented Programming</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,b10867fd-061a-48a0-9ff5-a2f72947f5a3.aspx</guid>
      <link>http://mokhan.ca/blog/2008/05/30/Studying+Object+Oriented+Programming.aspx</link>
      <pubDate>Fri, 30 May 2008 15:02:04 GMT</pubDate>
      <description>&lt;p&gt;
I'm currently reading...
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131489062%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Applying-UML-Patterns-Introduction-Object-Oriented/dp/0131489062%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/51aukquzeFL._SL75_.jpg" border="1" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design
and Iterative Development (3rd Edition)&lt;/b&gt; 
&lt;br /&gt;
by Craig Larman 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131489062%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Applying-UML-Patterns-Introduction-Object-Oriented/dp/0131489062%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this book...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
(I'm actually reading the 2nd edition)
&lt;/p&gt;
&lt;p&gt;
This is a good book. It started off really boring... really boring! I picked up this
book as an introduction to object oriented programming, and it started off with a
lot of talk on UML, documentation and the Rational Unified Process. But then I got
to chapter 16... &amp;quot;GRASP: Designing Objects with Responsibilities&amp;quot;.
&lt;/p&gt;
&lt;p&gt;
Here's an excerpt that I enjoyed!
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Perhaps the most common mistake when creating a domain model is to represent
something as an attribute when it should have been a concept. A rule of thumb to help
prevent this mistake is:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;If we do not think of some conceptual class X as a number or text in the real
world, X is probably a conceptual class, not an attribute&lt;/strong&gt;.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Here's a definition for a Domain Model...
&lt;/p&gt;
&lt;p&gt;
&amp;quot;The Domain Model provides a visual dictionary of the domain vocabulary and concepts
from which to draw inspiration for the naming of some things in the software design.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Chapter 16 is great so far, it talks about how to decompose responsibilities for objects
using an acronym (I'm not a fan of acronyms) called GRASP. GRASP stands for General
Responsibility Assignment Software Patterns. 
&lt;/p&gt;
&lt;p&gt;
Craig goes on to talk about the five different patterns of GRASP. They are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Information Expert&lt;/strong&gt;: the class that has the information necessary
to fulfill the responsibility.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Creator&lt;/strong&gt;: a class that has the responsibility to create an instance
of another class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High Cohesion&lt;/strong&gt;: increase the measure of how strongly related and focused
the responsibilities of an element are.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Low Coupling&lt;/strong&gt;: decrease the amount a class is connected to, has knowledge
of, or relies on other elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Controller:&lt;/strong&gt; a class with the responsibility of receiving or handling
a system event message.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b10867fd-061a-48a0-9ff5-a2f72947f5a3" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=b120efee-b59e-4da9-8516-76b9fe7e6ffc</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,b120efee-b59e-4da9-8516-76b9fe7e6ffc.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A great book to read is...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/519XT0DER6L._SL75_.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Refactoring: Improving the Design of Existing Code (The Addison-Wesley Object Technology
Series)</b>
                  <br />
by Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201485672%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Refactoring-Improving-Existing-Addison-Wesley-Technology/dp/0201485672%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
          <em>"Any fool can write code that a computer can understand. Good programmers
write code that humans can understand."</em>
        </p>
        <p>
"The first time you do something, you just do it. The second time you something
similar, you wince at the duplication, but you do the duplicate thing anyway. The
third time you do something similar, you refactor."
</p>
        <p>
          <strong>Introduce Local Extension:</strong> A server class you are using needs several
additional methods, but you can't modify the class.
</p>
        <p>
          <em>Create a new class that contains these extra methods. Make this extension class
a subclass or a wrapper of the original.</em>
        </p>
        <p>
          <em>E.g From this...</em>
        </p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">interface</span>
          <span style="color: rgb(43,145,175)">IController</span>{ <span style="color: rgb(0,0,255)">void</span> Execute();
} <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">class</span><span style="color: rgb(43,145,175)">Controller</span> : <span style="color: rgb(43,145,175)">IController</span> { <span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,255)">void</span> RenderView(<span style="color: rgb(0,0,255)">string</span> name, <span style="color: rgb(0,0,255)">object</span> data){ <span style="color: rgb(0,128,0)">//...
note that this is a protected method </span> } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Execute(){ <span style="color: rgb(0,128,0)">//... </span> }
}</pre>
        <p>
To this...
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">interface</span>
          <span style="color: rgb(43,145,175)">IViewRenderer</span>{ <span style="color: rgb(0,0,255)">void</span> Render&lt;T&gt;(<span style="color: rgb(0,0,255)">string</span> name,
T data); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">class</span><span style="color: rgb(43,145,175)">LocalExtensionController</span> : <span style="color: rgb(43,145,175)">Controller</span>, <span style="color: rgb(43,145,175)">IViewRenderer</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Render&lt;T&gt;(<span style="color: rgb(0,0,255)">string</span> name,
T data){ RenderView(name, data); } }</pre>
        <p>
          <strong>Replace Conditional with Polymorphism:</strong> You have a conditional that
chooses different behavior depending on the type of an object.
</p>
        <p>
          <em>Move each leg of the conditional to an overriding method in a subclass. Make the
original method abstract.</em>
        </p>
        <p>
          <em>E.g From this...</em>
        </p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">Bird</span>{ <span style="color: rgb(0,0,255)">public</span> Bird(<span style="color: rgb(43,145,175)">BirdType</span> type){
_type = type; } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">double</span> GetSpeed(){ <span style="color: rgb(0,0,255)">switch</span>(_type){ <span style="color: rgb(0,0,255)">case</span><span style="color: rgb(43,145,175)">BirdType</span>.EUROPEAN: <span style="color: rgb(0,0,255)">return</span> 5; <span style="color: rgb(0,0,255)">case</span><span style="color: rgb(43,145,175)">BirdType</span>.AFRICAN: <span style="color: rgb(0,0,255)">return</span> 10; <span style="color: rgb(0,0,255)">case</span><span style="color: rgb(43,145,175)">BirdType</span>.NORWEGIAN_BLUE: <span style="color: rgb(0,0,255)">return</span> 20;
} <span style="color: rgb(0,0,255)">throw</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">ArgumentException</span>();
} <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(43,145,175)">BirdType</span> _type;
} <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">enum</span><span style="color: rgb(43,145,175)">BirdType</span>{
EUROPEAN, AFRICAN, NORWEGIAN_BLUE }</pre>
        <p>
To this...
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">interface</span>
          <span style="color: rgb(43,145,175)">IBird</span>{ <span style="color: rgb(0,0,255)">double</span> GetSpeed();
} <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">class</span><span style="color: rgb(43,145,175)">EuropeanBird</span> : <span style="color: rgb(43,145,175)">IBird</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">double</span> GetSpeed(){ <span style="color: rgb(0,0,255)">return</span> 5;
} } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">class</span><span style="color: rgb(43,145,175)">AfricanBird</span> : <span style="color: rgb(43,145,175)">IBird</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">double</span> GetSpeed()
{ <span style="color: rgb(0,0,255)">return</span> 10; } } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">class</span><span style="color: rgb(43,145,175)">NorwegianBlueBird</span> : <span style="color: rgb(43,145,175)">IBird</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">double</span> GetSpeed()
{ <span style="color: rgb(0,0,255)">return</span> 20; } } </pre>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b120efee-b59e-4da9-8516-76b9fe7e6ffc" />
      </body>
      <title>Some More Refactorings...</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,b120efee-b59e-4da9-8516-76b9fe7e6ffc.aspx</guid>
      <link>http://mokhan.ca/blog/2008/05/23/Some+More+Refactorings.aspx</link>
      <pubDate>Fri, 23 May 2008 03:22:51 GMT</pubDate>
      <description>&lt;p&gt;
A great book to read is...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/519XT0DER6L._SL75_.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Refactoring: Improving the Design of Existing Code (The Addison-Wesley Object Technology
Series)&lt;/b&gt; 
&lt;br /&gt;
by Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201485672%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Refactoring-Improving-Existing-Addison-Wesley-Technology/dp/0201485672%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;&amp;quot;Any fool can write code that a computer can understand. Good programmers
write code that humans can understand.&amp;quot;&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;The first time you do something, you just do it. The second time you something
similar, you wince at the duplication, but you do the duplicate thing anyway. The
third time you do something similar, you refactor.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Introduce Local Extension:&lt;/strong&gt; A server class you are using needs several
additional methods, but you can't modify the class.
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;Create a new class that contains these extra methods. Make this extension class
a subclass or a wrapper of the original.&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;E.g From this...&lt;/em&gt;
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IController&lt;/span&gt;{ &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Execute();
} &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Controller&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;IController&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; RenderView(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; name, &lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt; data){ &lt;span style="color: rgb(0,128,0)"&gt;//...
note that this is a protected method &lt;/span&gt; } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Execute(){ &lt;span style="color: rgb(0,128,0)"&gt;//... &lt;/span&gt; }
}&lt;/pre&gt;
&lt;p&gt;
To this...
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IViewRenderer&lt;/span&gt;{ &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Render&amp;lt;T&amp;gt;(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; name,
T data); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;LocalExtensionController&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;Controller&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;IViewRenderer&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Render&amp;lt;T&amp;gt;(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; name,
T data){ RenderView(name, data); } }&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;Replace Conditional with Polymorphism:&lt;/strong&gt; You have a conditional that
chooses different behavior depending on the type of an object.
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;Move each leg of the conditional to an overriding method in a subclass. Make the
original method abstract.&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;E.g From this...&lt;/em&gt;
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Bird&lt;/span&gt;{ &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; Bird(&lt;span style="color: rgb(43,145,175)"&gt;BirdType&lt;/span&gt; type){
_type = type; } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;double&lt;/span&gt; GetSpeed(){ &lt;span style="color: rgb(0,0,255)"&gt;switch&lt;/span&gt;(_type){ &lt;span style="color: rgb(0,0,255)"&gt;case&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;BirdType&lt;/span&gt;.EUROPEAN: &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; 5; &lt;span style="color: rgb(0,0,255)"&gt;case&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;BirdType&lt;/span&gt;.AFRICAN: &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; 10; &lt;span style="color: rgb(0,0,255)"&gt;case&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;BirdType&lt;/span&gt;.NORWEGIAN_BLUE: &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; 20;
} &lt;span style="color: rgb(0,0,255)"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ArgumentException&lt;/span&gt;();
} &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;BirdType&lt;/span&gt; _type;
} &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;enum&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;BirdType&lt;/span&gt;{
EUROPEAN, AFRICAN, NORWEGIAN_BLUE }&lt;/pre&gt;
&lt;p&gt;
To this...
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IBird&lt;/span&gt;{ &lt;span style="color: rgb(0,0,255)"&gt;double&lt;/span&gt; GetSpeed();
} &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EuropeanBird&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;IBird&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;double&lt;/span&gt; GetSpeed(){ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; 5;
} } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;AfricanBird&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;IBird&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;double&lt;/span&gt; GetSpeed()
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; 10; } } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;NorwegianBlueBird&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;IBird&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;double&lt;/span&gt; GetSpeed()
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; 20; } } &lt;/pre&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b120efee-b59e-4da9-8516-76b9fe7e6ffc" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=f1f69d3e-6456-4e60-96be-f2ff441f0eec</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,f1f69d3e-6456-4e60-96be-f2ff441f0eec.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A couple of months ago I finished reading... 
</p>
        <table border="0">
          <tbody>
            <tr>
              <td valign="top">
                <a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131495054%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/xUnit-Test-Patterns-Refactoring-Addison-Wesley/dp/0131495054%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">
                  <img src="http://ecx.images-amazon.com/images/I/51ZfuTVoX0L._SL75_.jpg" border="1" />
                </a>
              </td>
              <td valign="top">
                <b>xUnit Test Patterns: Refactoring Test Code (The Addison-Wesley Signature Series)</b>
                <br />
by Gerard Meszaros 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131495054%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/xUnit-Test-Patterns-Refactoring-Addison-Wesley/dp/0131495054%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this book...</a></td>
            </tr>
          </tbody>
        </table>
        <p>
 
</p>
        <p>
This was a thick book, that discusses unit test smells, unit test refactorings, unit
test patterns... and just about anything else related to unit testing. Here's a little
of what I've learned from this book...
</p>
        <h3>Defect Localization
</h3>
        <p>
"Mistakes happen! Of course, some mistakes are much more expensive to prevent
than to fix. Suppose a bug does slip through somehow and shows up in the Integration
Build. If our unit test are fairly small (i.e., we test only a single behavior in
each one), we should be able to pinpoint the bug quickly based on which test fails.
This specificity is one of the major advantages that unit tests enjoy over customer
tests. The customer tests tell us that some behavior expected by the customer isn't
working; the unit tests tell us why. We call this phenomenon Defect Localization.
If a customer test fails but no unit tests fail, it indicates a Missing Unit Test."
</p>
        <h3>Tests as Documentation
</h3>
        <p>
"Without automated tests, we would need to pore over the SUT code trying to answer
the question, 'What should be the result if ...?' With automated tests, we simply
use the corresponding Tests as Documentation; they tell us what the result should
be. If we want to know how the system does something, we can turn on the debugger,
run the test, and single-step through the code to see how it works. In this sense,
the automated tests act as a form of documentation for the SUT."
</p>
        <p>
"When it is not important for something to be seen in the test method, it is
important that it <strong>not</strong> be seen in the test method!"
</p>
        <h3>Test Doubles
</h3>
        <p>
A test double is any object or component that we install in place of the real component
for the express purpose of running a test. Depending on the reason why we are using
it, a Test Double can behave in one of four ways.
</p>
        <ul>
          <li>
Dummy Object: a object that is passed to the SUT as an argument but is never actually
used. 
</li>
          <li>
Test Stub: an object that replaces a real component on that the SUT depends on so
that different <strong>inputs</strong> can by applied against the SUT. 
</li>
          <li>
Test Spy: an object that can act as an observation point for the indirect outputs
of the SUT. 
</li>
          <li>
Mock Object: an object that replaces a real component that the SUT depends on to test
the and verify indirect <strong>outputs</strong>. 
</li>
          <li>
Fake Object: an object that replaces the functionality of the real SUT dependency
with an alternate implementation that provides the same functionality. 
</li>
        </ul>
        <h3>Strict vs Loose
</h3>
        <p>
Mock objects come in two basic flavors:
</p>
        <ul>
          <li>
Strict Mock: fails the test if incorrect calls are received. 
</li>
          <li>
Loose (lenient) Mock: fails if expected calls are not received, but is lenient if
additional calls are received. 
</li>
        </ul>
        <h3>Need-Driven Development
</h3>
        <p>
"This 'outside-in' approach to writing and testing software combines the conceptual
elegance of the traditional 'top-down' approach to writing code with modern TDD techniques
supported by Mock Objects. It allows us to build and test the software layer by layer,
starting at the outermost layer before we have implemented the lower layers."
</p>
        <h3>Test Smells
</h3>
        <p>
"Developers Not Writing Tests may be caused by an overly aggressive development
schedule, supervisors who tell developers not to 'waste time writing tests,' or developers
who do not have the skills to write tests. Other potential causes might include an
imposed design that is not conducive to testing or a test environment that leads to
Fragile Tests. Finally, this problem could result from Lost Tests - tests that exist
but are not included in the All Tests Suite used by developers during check-in or
by the automated build tool."
</p>
        <p>
"Another productivity-sapping smell is Frequent Debugging. Automated unit tests
should obviate the need to use a debugger in all but rare cases, because the set of
tests that are failing should make it obvious why the failure is occurring. Frequent
Debugging is a sign that the unit tests are lacking in coverage or are trying to test
to much functionality at once."
</p>
        <p>
Fragile Test: "A test fails to compile or run when the SUT is changed in ways
that do not affect the part the is exercising... Fragile tests increase the cost of
test maintenance by forcing us to visit many more tests each time we modify the functionality
of the system or the fixture."
</p>
        <p>
This headache is typical if you're working with strict mock objects. I experienced
this pain when working on a project using NMock. I couldn't find a clean separation
between strict and loose mocks using NMock. There was only the concept of Strict Mocks
and Stubs.
</p>
        <p>
Slow Tests: "The tests take too long to run... They reduce the productivity of
the person running the test. Instead, the developers wait until the next coffee break
or another interruption before running them. Or, whenever they run the tests, they
walk around and chat with other team members..."
</p>
        <p>
The main disadvantages of using Fit are described here:
</p>
        <ul>
          <li>
The test scenarios need to be very well understood before we can build the Fit Fixture.
We then need to translate each test's logic into a tabular representation; this isn't
always a good fit. 
</li>
          <li>
The tests need to employ the same SUT interaction logic in each test. To run several
different styles of tests, we would probably have to build one or more different fixtures
for each style of test. Building a new fixture is typically more complex than writing
a few Test Methods. 
</li>
          <li>
Fit tests aren't normally integrated into developers' regression tests that are run
via xUnit. Instead, these test must be run separately - which introduces the possibility
that they will not be run at each check-in. 
</li>
        </ul>
        <h3>Pull
</h3>
        <p>
"A concept from lean manufacturing that states that things should be produced
only once a real demand for them exists. In a 'pull system,' upstream assembly lines
produce only enough products to replace the items withdrawn from the pool that buffers
them from the downstream assembly lines. In software development, this idea can be
translated as follows: 'We should only write methods that have already been called
by other software and only handle those cases that the other software actually needs.'
This approach avoids speculation and the writing of unnecessary software, which is
one of software development's key forms of inventory (which is considered waste in
lean systems)."
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=f1f69d3e-6456-4e60-96be-f2ff441f0eec" />
      </body>
      <title>Got Tests?</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,f1f69d3e-6456-4e60-96be-f2ff441f0eec.aspx</guid>
      <link>http://mokhan.ca/blog/2008/05/21/Got+Tests.aspx</link>
      <pubDate>Wed, 21 May 2008 18:30:53 GMT</pubDate>
      <description>&lt;p&gt;
A couple of months ago I finished reading... 
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131495054%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/xUnit-Test-Patterns-Refactoring-Addison-Wesley/dp/0131495054%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/51ZfuTVoX0L._SL75_.jpg" border="1" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;xUnit Test Patterns: Refactoring Test Code (The Addison-Wesley Signature Series)&lt;/b&gt; 
&lt;br /&gt;
by Gerard Meszaros 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131495054%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/xUnit-Test-Patterns-Refactoring-Addison-Wesley/dp/0131495054%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this book...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
This was a thick book, that discusses unit test smells, unit test refactorings, unit
test patterns... and just about anything else related to unit testing. Here's a little
of what I've learned from this book...
&lt;/p&gt;
&lt;h3&gt;Defect Localization
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;Mistakes happen! Of course, some mistakes are much more expensive to prevent
than to fix. Suppose a bug does slip through somehow and shows up in the Integration
Build. If our unit test are fairly small (i.e., we test only a single behavior in
each one), we should be able to pinpoint the bug quickly based on which test fails.
This specificity is one of the major advantages that unit tests enjoy over customer
tests. The customer tests tell us that some behavior expected by the customer isn't
working; the unit tests tell us why. We call this phenomenon Defect Localization.
If a customer test fails but no unit tests fail, it indicates a Missing Unit Test.&amp;quot;
&lt;/p&gt;
&lt;h3&gt;Tests as Documentation
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;Without automated tests, we would need to pore over the SUT code trying to answer
the question, 'What should be the result if ...?' With automated tests, we simply
use the corresponding Tests as Documentation; they tell us what the result should
be. If we want to know how the system does something, we can turn on the debugger,
run the test, and single-step through the code to see how it works. In this sense,
the automated tests act as a form of documentation for the SUT.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;When it is not important for something to be seen in the test method, it is
important that it &lt;strong&gt;not&lt;/strong&gt; be seen in the test method!&amp;quot;
&lt;/p&gt;
&lt;h3&gt;Test Doubles
&lt;/h3&gt;
&lt;p&gt;
A test double is any object or component that we install in place of the real component
for the express purpose of running a test. Depending on the reason why we are using
it, a Test Double can behave in one of four ways.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Dummy Object: a object that is passed to the SUT as an argument but is never actually
used. 
&lt;/li&gt;
&lt;li&gt;
Test Stub: an object that replaces a real component on that the SUT depends on so
that different &lt;strong&gt;inputs&lt;/strong&gt; can by applied against the SUT. 
&lt;/li&gt;
&lt;li&gt;
Test Spy: an object that can act as an observation point for the indirect outputs
of the SUT. 
&lt;/li&gt;
&lt;li&gt;
Mock Object: an object that replaces a real component that the SUT depends on to test
the and verify indirect &lt;strong&gt;outputs&lt;/strong&gt;. 
&lt;/li&gt;
&lt;li&gt;
Fake Object: an object that replaces the functionality of the real SUT dependency
with an alternate implementation that provides the same functionality. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Strict vs Loose
&lt;/h3&gt;
&lt;p&gt;
Mock objects come in two basic flavors:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Strict Mock: fails the test if incorrect calls are received. 
&lt;/li&gt;
&lt;li&gt;
Loose (lenient) Mock: fails if expected calls are not received, but is lenient if
additional calls are received. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Need-Driven Development
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;This 'outside-in' approach to writing and testing software combines the conceptual
elegance of the traditional 'top-down' approach to writing code with modern TDD techniques
supported by Mock Objects. It allows us to build and test the software layer by layer,
starting at the outermost layer before we have implemented the lower layers.&amp;quot;
&lt;/p&gt;
&lt;h3&gt;Test Smells
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;Developers Not Writing Tests may be caused by an overly aggressive development
schedule, supervisors who tell developers not to 'waste time writing tests,' or developers
who do not have the skills to write tests. Other potential causes might include an
imposed design that is not conducive to testing or a test environment that leads to
Fragile Tests. Finally, this problem could result from Lost Tests - tests that exist
but are not included in the All Tests Suite used by developers during check-in or
by the automated build tool.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Another productivity-sapping smell is Frequent Debugging. Automated unit tests
should obviate the need to use a debugger in all but rare cases, because the set of
tests that are failing should make it obvious why the failure is occurring. Frequent
Debugging is a sign that the unit tests are lacking in coverage or are trying to test
to much functionality at once.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Fragile Test: &amp;quot;A test fails to compile or run when the SUT is changed in ways
that do not affect the part the is exercising... Fragile tests increase the cost of
test maintenance by forcing us to visit many more tests each time we modify the functionality
of the system or the fixture.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
This headache is typical if you're working with strict mock objects. I experienced
this pain when working on a project using NMock. I couldn't find a clean separation
between strict and loose mocks using NMock. There was only the concept of Strict Mocks
and Stubs.
&lt;/p&gt;
&lt;p&gt;
Slow Tests: &amp;quot;The tests take too long to run... They reduce the productivity of
the person running the test. Instead, the developers wait until the next coffee break
or another interruption before running them. Or, whenever they run the tests, they
walk around and chat with other team members...&amp;quot;
&lt;/p&gt;
&lt;p&gt;
The main disadvantages of using Fit are described here:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The test scenarios need to be very well understood before we can build the Fit Fixture.
We then need to translate each test's logic into a tabular representation; this isn't
always a good fit. 
&lt;/li&gt;
&lt;li&gt;
The tests need to employ the same SUT interaction logic in each test. To run several
different styles of tests, we would probably have to build one or more different fixtures
for each style of test. Building a new fixture is typically more complex than writing
a few Test Methods. 
&lt;/li&gt;
&lt;li&gt;
Fit tests aren't normally integrated into developers' regression tests that are run
via xUnit. Instead, these test must be run separately - which introduces the possibility
that they will not be run at each check-in. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Pull
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;A concept from lean manufacturing that states that things should be produced
only once a real demand for them exists. In a 'pull system,' upstream assembly lines
produce only enough products to replace the items withdrawn from the pool that buffers
them from the downstream assembly lines. In software development, this idea can be
translated as follows: 'We should only write methods that have already been called
by other software and only handle those cases that the other software actually needs.'
This approach avoids speculation and the writing of unnecessary software, which is
one of software development's key forms of inventory (which is considered waste in
lean systems).&amp;quot;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=f1f69d3e-6456-4e60-96be-f2ff441f0eec" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=9f22ad6d-7ac4-408f-8e80-884982c61d29</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,9f22ad6d-7ac4-408f-8e80-884982c61d29.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm just about finished reading... 
</p>
        <table border="0">
          <tbody>
            <tr>
              <td valign="top">
                <a href="http://www.amazon.com/gp/redirect.html%3FASIN=0977616630%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Agile-Web-Development-Rails-2nd/dp/0977616630%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">
                  <img src="http://ecx.images-amazon.com/images/I/51YZKK7C2WL._SL75_.jpg" border="1" />
                </a>
              </td>
              <td valign="top">
                <b>Agile Web Development with Rails, 2nd Edition</b>
                <br />
by Dave Thomas, David Hansson, Leon Breedt, Mike Clark, James Duncan Davidson, Justin
Gehtland, Andreas Schwarz 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0977616630%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Agile-Web-Development-Rails-2nd/dp/0977616630%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this book...</a></td>
            </tr>
          </tbody>
        </table>
        <p>
 
</p>
        <p>
This book focuses on the Ruby on Rails framework for developing web applications.
It touches very lightly on the Ruby language itself, but mostly talks about things
like Model View Controller, Active Record, Action Pack and how it's implemented in
RoR's. The book starts off with a light primer on what MVC is, which I enjoyed, then
moves on to how to install RoR, then jumps right into building a quick application
using RoR. I enjoyed the discussion Testing and the concept of Migrations.
</p>
        <p>
Before jumping right in to chapter one I quickly read through the first Appendix titled
"Introduction to Ruby", which helped a little bit, but I probably would
have done better if I had first read a book just on the Ruby language. I think I would
have found it more interesting as well. There were times in the book where it got
so deep into the nitty gritty details of the RoR framework that I just completely
lost interest. I choose to read this book to get some high level ideas, but I wasn't
as interested in the tiny details of the framework. There's tonnes of great ideas
in this book, that I recognize being adopted quite a bit in the .NET community. Migrations
and MVC being a couple of my favorites.
</p>
        <p>
Here's a few excerpts that I enjoyed from this book...
</p>
        <h3>Convention over Configuration
</h3>
        <p>
"Rails gives you lots of opportunities to override this basic workflow ... As
it stands, our story illustrates convention over configuration, one of the fundamental
parts of the philosophy of Rails. By providing convenient defaults and by applying
certain conventions, Rails applications are typically written using little or no external
configuration - things just knit themselves together in a natural way."
</p>
        <h3>Migrations
</h3>
        <p>
"Over the years, developers have come up with ways of dealing with this issue.
One scheme is to keep the Data Definition Language (DDL) statements that define the
schema in source form under version control. Whenever you change the schema, you edit
this file to reflect the changes. You then drop your development database and re-create
the schema from scratch by applying your DDL. If you need to roll back a week, the
application code and the DDL that you check out from the version control system are
in step: when you re-create the schema from the DDL, your database will have gone
back in time.
</p>
        <p>
Except... because you drop the database every time you apply the DDL, you lose any
data in your development database. Wouldn't it be more convenient to be able to apply
only those changes that are necessary to move a database from version X to version
Y? this is exactly what Rails migrations let you do."
</p>
        <p>
E.g. 001_create_products.rb
</p>
        <p>
class CreateProducts &lt; ActiveRecord:Migration 
<br />
    def self.up 
<br />
        create_table :products do |t| 
<br />
            t.column :title,       
:string 
<br />
            t.column :description   
:text 
<br />
            t.column :image_url       
:string 
<br />
        end 
<br />
    end 
<br />
    def self.down 
<br />
        drop_table :products 
<br />
    end 
<br />
end
</p>
        <h3>Pragmatic Ajax-ification
</h3>
        <p>
"In the old days, browsers were treated as really dumb devices. When you wrote
a browser-based application, you'd send stuff down to the browser and then forget
about that session. At some point, the user would fill in some form fields or click
a hyperlink, and your application would get woken up by an incoming request. It would
render a complete page back to the user, and the whole tedious process would start
afresh...
</p>
        <p>
Whenever you work with AJAX, <strong>it's good to start with the non-AJAX version
of the application and then gradually introduce AJAX features</strong>."
</p>
        <h3>No REST For The Wicked
</h3>
        <p>
"REST stands for REpresentational State Transfer, which is basically meaningless.
What it really means is that you use HTTP verbs (GET, POST, DELETE, and so on) to
send requests and responses between applications."
</p>
        <h3>Performance Testing
</h3>
        <p>
"Testing isn't just about whether something does what it should. We might also
want to know whether it does it fast enough.
</p>
        <p>
Before we get to deep into this, here's a warning. Most applications perform just
fine most of the time, and when they do start to get slow, it's often in ways we would
never have anticipated. For this reason, <strong>it's normally a bad idea to focus
on performance early in development</strong>. Instead, we recommend using performance
testing in two scenarios, both late in the development process."
</p>
        <h3>Statement Modifiers
</h3>
        <p>
"Ruby statement modifiers are a useful shortcut if the body of an if or while
statement is just a single expression. Simply write the expression, followed by <em>if</em> or <em>while</em> and
the condition."
</p>
        <p>
The following is valid Ruby syntax:
</p>
        <p>
puts "Danger, Will Robinson" <strong>if</strong> radiation &gt; 3000
</p>
        <p>
I would love to express the following C# syntax....
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">void</span> AddLicense(<span style="color: rgb(43,145,175)">ILicense</span> license){ <span style="color: rgb(0,0,255)">if</span>(license.IsValid()){
licenseRepository.Add(license); } }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
Like this...
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">void</span> AddLicense(<span style="color: rgb(43,145,175)">ILicense</span> license){
licenseRepository.Add(license).If(license.IsValid()); }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=9f22ad6d-7ac4-408f-8e80-884982c61d29" />
      </body>
      <title>Spikin' Ruby on Rails</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,9f22ad6d-7ac4-408f-8e80-884982c61d29.aspx</guid>
      <link>http://mokhan.ca/blog/2008/05/21/Spikin+Ruby+On+Rails.aspx</link>
      <pubDate>Wed, 21 May 2008 15:22:47 GMT</pubDate>
      <description>&lt;p&gt;
I'm just about finished reading... 
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0977616630%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Agile-Web-Development-Rails-2nd/dp/0977616630%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/51YZKK7C2WL._SL75_.jpg" border="1" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Agile Web Development with Rails, 2nd Edition&lt;/b&gt; 
&lt;br /&gt;
by Dave Thomas, David Hansson, Leon Breedt, Mike Clark, James Duncan Davidson, Justin
Gehtland, Andreas Schwarz 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0977616630%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/Agile-Web-Development-Rails-2nd/dp/0977616630%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this book...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
This book focuses on the Ruby on Rails framework for developing web applications.
It touches very lightly on the Ruby language itself, but mostly talks about things
like Model View Controller, Active Record, Action Pack and how it's implemented in
RoR's. The book starts off with a light primer on what MVC is, which I enjoyed, then
moves on to how to install RoR, then jumps right into building a quick application
using RoR. I enjoyed the discussion Testing and the concept of Migrations.
&lt;/p&gt;
&lt;p&gt;
Before jumping right in to chapter one I quickly read through the first Appendix titled
&amp;quot;Introduction to Ruby&amp;quot;, which helped a little bit, but I probably would
have done better if I had first read a book just on the Ruby language. I think I would
have found it more interesting as well. There were times in the book where it got
so deep into the nitty gritty details of the RoR framework that I just completely
lost interest. I choose to read this book to get some high level ideas, but I wasn't
as interested in the tiny details of the framework. There's tonnes of great ideas
in this book, that I recognize being adopted quite a bit in the .NET community. Migrations
and MVC being a couple of my favorites.
&lt;/p&gt;
&lt;p&gt;
Here's a few excerpts that I enjoyed from this book...
&lt;/p&gt;
&lt;h3&gt;Convention over Configuration
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;Rails gives you lots of opportunities to override this basic workflow ... As
it stands, our story illustrates convention over configuration, one of the fundamental
parts of the philosophy of Rails. By providing convenient defaults and by applying
certain conventions, Rails applications are typically written using little or no external
configuration - things just knit themselves together in a natural way.&amp;quot;
&lt;/p&gt;
&lt;h3&gt;Migrations
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;Over the years, developers have come up with ways of dealing with this issue.
One scheme is to keep the Data Definition Language (DDL) statements that define the
schema in source form under version control. Whenever you change the schema, you edit
this file to reflect the changes. You then drop your development database and re-create
the schema from scratch by applying your DDL. If you need to roll back a week, the
application code and the DDL that you check out from the version control system are
in step: when you re-create the schema from the DDL, your database will have gone
back in time.
&lt;/p&gt;
&lt;p&gt;
Except... because you drop the database every time you apply the DDL, you lose any
data in your development database. Wouldn't it be more convenient to be able to apply
only those changes that are necessary to move a database from version X to version
Y? this is exactly what Rails migrations let you do.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
E.g. 001_create_products.rb
&lt;/p&gt;
&lt;p&gt;
class CreateProducts &amp;lt; ActiveRecord:Migration 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; def self.up 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; create_table :products do |t| 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; t.column :title,&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
:string 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; t.column :description&amp;#160;&amp;#160;&amp;#160;
:text 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; t.column :image_url&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
:string 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; end 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; end 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; def self.down 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; drop_table :products 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; end 
&lt;br /&gt;
end
&lt;/p&gt;
&lt;h3&gt;Pragmatic Ajax-ification
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;In the old days, browsers were treated as really dumb devices. When you wrote
a browser-based application, you'd send stuff down to the browser and then forget
about that session. At some point, the user would fill in some form fields or click
a hyperlink, and your application would get woken up by an incoming request. It would
render a complete page back to the user, and the whole tedious process would start
afresh...
&lt;/p&gt;
&lt;p&gt;
Whenever you work with AJAX, &lt;strong&gt;it's good to start with the non-AJAX version
of the application and then gradually introduce AJAX features&lt;/strong&gt;.&amp;quot;
&lt;/p&gt;
&lt;h3&gt;No REST For The Wicked
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;REST stands for REpresentational State Transfer, which is basically meaningless.
What it really means is that you use HTTP verbs (GET, POST, DELETE, and so on) to
send requests and responses between applications.&amp;quot;
&lt;/p&gt;
&lt;h3&gt;Performance Testing
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;Testing isn't just about whether something does what it should. We might also
want to know whether it does it fast enough.
&lt;/p&gt;
&lt;p&gt;
Before we get to deep into this, here's a warning. Most applications perform just
fine most of the time, and when they do start to get slow, it's often in ways we would
never have anticipated. For this reason, &lt;strong&gt;it's normally a bad idea to focus
on performance early in development&lt;/strong&gt;. Instead, we recommend using performance
testing in two scenarios, both late in the development process.&amp;quot;
&lt;/p&gt;
&lt;h3&gt;Statement Modifiers
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;Ruby statement modifiers are a useful shortcut if the body of an if or while
statement is just a single expression. Simply write the expression, followed by &lt;em&gt;if&lt;/em&gt; or &lt;em&gt;while&lt;/em&gt; and
the condition.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
The following is valid Ruby syntax:
&lt;/p&gt;
&lt;p&gt;
puts &amp;quot;Danger, Will Robinson&amp;quot; &lt;strong&gt;if&lt;/strong&gt; radiation &amp;gt; 3000
&lt;/p&gt;
&lt;p&gt;
I would love to express the following C# syntax....
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; AddLicense(&lt;span style="color: rgb(43,145,175)"&gt;ILicense&lt;/span&gt; license){ &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(license.IsValid()){
licenseRepository.Add(license); } }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Like this...
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; AddLicense(&lt;span style="color: rgb(43,145,175)"&gt;ILicense&lt;/span&gt; license){
licenseRepository.Add(license).If(license.IsValid()); }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=9f22ad6d-7ac4-408f-8e80-884982c61d29" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=28005b64-d91e-4441-95d9-f56ed9c63b0a</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,28005b64-d91e-4441-95d9-f56ed9c63b0a.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm still reading...
</p>
        <table border="0">
          <tbody>
            <tr>
              <td valign="top">
                <a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201310058%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201310058%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">
                  <img src="http://ecx.images-amazon.com/images/I/51FKSNAV2GL._SL75_.jpg" border="1" />
                </a>
              </td>
              <td valign="top">
                <b>Effective Java(TM) Programming Language Guide (The Java Series)</b>
                <br />
by Joshua Bloch 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201310058%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201310058%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this book...</a></td>
            </tr>
          </tbody>
        </table>
        <p>
 
</p>
        <p>
Here's a few quotes from the book, that I found interesting: 
</p>
        <p>
"We should forget about small efficiencies, say about 97% of the time: premature
optimization is the root of all evil." - Donald E. Knuth
</p>
        <p>
"Don't sacrifice sound architectural principles for performance. Strive to write
good programs rather than fast ones. If a good program is not fast enough, its architecture
will allow it to be optimized. Good programs embody the principle of information hiding:
Where possible, they localize design decisions within individual modules, so individual
decisions can be changed without affecting the remainder of the system."
</p>
        <p>
A typical example of pre-mature optimization is thinking about "database calls"
when working up in a UI layer. These are two completely separate architectural layers
and should be developed without "optimization" constraints in mind. 
</p>
        <p>
For example:
</p>
        <p>
"...we have to check if its a post back, to make sure we don't make another database
hit. If we retrieve the contents of the page each time the page is requested that's
going to be another database hit."
</p>
        <p>
Relax... there are lots of techniques (lazy loading, identity map...) to improve performance <strong>if
it's an issue</strong>. But optimizing the UI for database performance is weak, and
will more than likely cause you to build a crippled UI layer before even hitting the
lower layers. 
</p>
        <p>
"Often attempted optimizations have no measurable effect on performance; sometimes
they make it worse." 
</p>
        <p>
If we take the above example, if you're constantly "optimizing" for database
performance be weary of what it's costing you. E.g... ViewState, extra conditional
code that's sooo freakin' impossible to understand, that no dev wants to come back
and touch <strong>that</strong> code.
</p>
        <p>
It can be pointless to try to find solutions to a problem that doesn't exist.
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=28005b64-d91e-4441-95d9-f56ed9c63b0a" />
      </body>
      <title>Stop Optimizing</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,28005b64-d91e-4441-95d9-f56ed9c63b0a.aspx</guid>
      <link>http://mokhan.ca/blog/2008/04/23/Stop+Optimizing.aspx</link>
      <pubDate>Wed, 23 Apr 2008 15:06:55 GMT</pubDate>
      <description>&lt;p&gt;
I'm still reading...
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201310058%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201310058%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/51FKSNAV2GL._SL75_.jpg" border="1" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Effective Java(TM) Programming Language Guide (The Java Series)&lt;/b&gt; 
&lt;br /&gt;
by Joshua Bloch 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201310058%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201310058%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this book...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Here's a few quotes from the book, that I found interesting: 
&lt;/p&gt;
&lt;p&gt;
&amp;quot;We should forget about small efficiencies, say about 97% of the time: premature
optimization is the root of all evil.&amp;quot; - Donald E. Knuth
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Don't sacrifice sound architectural principles for performance. Strive to write
good programs rather than fast ones. If a good program is not fast enough, its architecture
will allow it to be optimized. Good programs embody the principle of information hiding:
Where possible, they localize design decisions within individual modules, so individual
decisions can be changed without affecting the remainder of the system.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
A typical example of pre-mature optimization is thinking about &amp;quot;database calls&amp;quot;
when working up in a UI layer. These are two completely separate architectural layers
and should be developed without &amp;quot;optimization&amp;quot; constraints in mind. 
&lt;/p&gt;
&lt;p&gt;
For example:
&lt;/p&gt;
&lt;p&gt;
&amp;quot;...we have to check if its a post back, to make sure we don't make another database
hit. If we retrieve the contents of the page each time the page is requested that's
going to be another database hit.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Relax... there are lots of techniques (lazy loading, identity map...) to improve performance &lt;strong&gt;if
it's an issue&lt;/strong&gt;. But optimizing the UI for database performance is weak, and
will more than likely cause you to build a crippled UI layer before even hitting the
lower layers. 
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Often attempted optimizations have no measurable effect on performance; sometimes
they make it worse.&amp;quot; 
&lt;/p&gt;
&lt;p&gt;
If we take the above example, if you're constantly &amp;quot;optimizing&amp;quot; for database
performance be weary of what it's costing you. E.g... ViewState, extra conditional
code that's sooo freakin' impossible to understand, that no dev wants to come back
and touch &lt;strong&gt;that&lt;/strong&gt; code.
&lt;/p&gt;
&lt;p&gt;
It can be pointless to try to find solutions to a problem that doesn't exist.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=28005b64-d91e-4441-95d9-f56ed9c63b0a" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=a7e867f2-119a-48ca-a668-4155125fe964</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,a7e867f2-119a-48ca-a668-4155125fe964.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm currently reading...
</p>
        <table border="0">
          <tbody>
            <tr>
              <td valign="top">
                <a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201310058%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201310058%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">
                  <img src="http://ecx.images-amazon.com/images/I/51FKSNAV2GL._SL75_.jpg" border="1" />
                </a>
              </td>
              <td valign="top">
                <b>Effective Java(TM) Programming Language Guide (The Java Series)</b>
                <br />
by Joshua Bloch 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201310058%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201310058%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this book...</a></td>
            </tr>
          </tbody>
        </table>
        <p>
 
</p>
        <p>
I thought I would share en excerpt that I read this morning on the bus... it's about
my favorite topic: Implementation Inheritance.
</p>
        <p>
"Inheritance is a powerful way to achieve code reuse, but it is <strong>not always
the best tool for the job</strong>. Used inappropriately, it leads to fragile software.
It is safe to use inheritance within a package, where the subclass and the superclass
implementation are under the control of the same programmers. It is also safe to use
inheritance when extending classes specifically designed and documented for extension.
Inheriting from ordinary concrete classes across package boundaries, however, is dangerous.
As a reminder, this book uses the word <strong>'inheritance' to mean 'implementation
inheritance'</strong> (when one class extends another). The problems discussed in
this item <strong>do not apply to <em>interface inheritance</em></strong> (when a
class implements an interface or where one interface extends another)."
</p>
        <p>
"Unlike method invocation, <strong>inheritance breaks encapsulation</strong>.
In other words, a subclass depends on the implementation details of its superclass
for its proper function."
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=a7e867f2-119a-48ca-a668-4155125fe964" />
      </body>
      <title>Inherently Undesirable</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,a7e867f2-119a-48ca-a668-4155125fe964.aspx</guid>
      <link>http://mokhan.ca/blog/2008/04/16/Inherently+Undesirable.aspx</link>
      <pubDate>Wed, 16 Apr 2008 19:14:11 GMT</pubDate>
      <description>&lt;p&gt;
I'm currently reading...
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201310058%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201310058%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/51FKSNAV2GL._SL75_.jpg" border="1" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Effective Java(TM) Programming Language Guide (The Java Series)&lt;/b&gt; 
&lt;br /&gt;
by Joshua Bloch 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201310058%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201310058%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this book...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
I thought I would share en excerpt that I read this morning on the bus... it's about
my favorite topic: Implementation Inheritance.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Inheritance is a powerful way to achieve code reuse, but it is &lt;strong&gt;not always
the best tool for the job&lt;/strong&gt;. Used inappropriately, it leads to fragile software.
It is safe to use inheritance within a package, where the subclass and the superclass
implementation are under the control of the same programmers. It is also safe to use
inheritance when extending classes specifically designed and documented for extension.
Inheriting from ordinary concrete classes across package boundaries, however, is dangerous.
As a reminder, this book uses the word &lt;strong&gt;'inheritance' to mean 'implementation
inheritance'&lt;/strong&gt; (when one class extends another). The problems discussed in
this item &lt;strong&gt;do not apply to &lt;em&gt;interface inheritance&lt;/em&gt;&lt;/strong&gt; (when a
class implements an interface or where one interface extends another).&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Unlike method invocation, &lt;strong&gt;inheritance breaks encapsulation&lt;/strong&gt;.
In other words, a subclass depends on the implementation details of its superclass
for its proper function.&amp;quot;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=a7e867f2-119a-48ca-a668-4155125fe964" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=45cf5343-1845-4ebe-bf63-8b5cb93550af</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,45cf5343-1845-4ebe-bf63-8b5cb93550af.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently finished reading...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/01AYLg-qlrL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>C# 3.0 in a Nutshell: A Desktop Quick Reference (In a Nutshell (O'Reilly))</b>
                  <br />
by Joseph Albahari, Ben Albahari 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596527578%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596527578%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
My desire to read this book was to understand what new language features C# 3.0 brings
to the table. This book started to explain the C# language right from the very beginning
up until now. So some of it was a great refresher and some of it was quite boring.
It not only covers the new language features but covers several areas of the framework
class libraries and new lib's that came with the .NET 3.5 stack. 
</p>
        <p>
I was hoping to find my coverage on the new language features to see different usages
for things like extension methods and lambda's to try to get a sense for what I like
and don't like. So far I'm not really a fan of the new query comprehension syntax.
It's to SQL-ish for me... I prefer working directly against methods. But I might have
to give it some time... enough ranting here's some of the things I've learned.
</p>
        <h3>Lambda Expressions
</h3>
        <p>
There's tonnes, and tonnes of discussion on this topic right now. I love how it's
so much cleaner, and less verbose then anonymous delegates, but I see potential room
for abuse. IMHO seeing lambda's tossed around all over your code base is no better
then over using anonymous delegates. I love the new ideas that lambda's bring though...
</p>
        <p>
"A lambda expression is an unnamed method written in place of a delegate instance.
The compiler immediately converts the lambda expression to either:
</p>
        <ul>
          <li>
A delegate instance. 
</li>
          <li>
An expression tree, of type Expression&lt;T&gt;, representing the code inside the
lambda expression in a traversable object model. This allows the lambda expression
to be interpreted later at runtime..." - <strong>C# 3.0 in a Nutshell</strong></li>
        </ul>
        <p>
I love the idea of building up an expression tree of delegates that chain together
to solve an equation. One of the ideas I'm working on is understanding how to leverage
an expression tree of lambdas to solve trivial mathematical equations. Then possible
traversing through the structure with a visitor to build out a display friendly version
of the equation.
</p>
        <h3>WPF
</h3>
        <p>
"The benefits of WPF are as follows:
</p>
        <ul>
          <li>
It supports sophisticated graphics, such as arbitrary transformations, 3D rendering,
and true transparency. 
</li>
          <li>
Its primary measurement unit is not pixel-based, so applications display correctly
in any DPI 
</li>
          <li>
It has extensive dynamic layout support, which means you can localize any application
without danger of elements overlapping. 
</li>
          <li>
Rendering uses DirectX and is fast, taking good advantage of graphics hardware acceleration. 
</li>
          <li>
User interfaces can be described declaratively in XAML files that can be maintained
independently of the "code-behind" files - this helps to separate appearance
from functionality." - <strong>C# 3.0 in a Nutshell</strong></li>
        </ul>
        <h3>WCF
</h3>
        <p>
"WCF is the communication infrastructure new to Framework 3.0. WCF is flexible
and configurable enough to make both of its predecessors - Remoting and (.ASMX) Web
Services - mostly redundant." - <strong>C# 3.0 in a Nutshell</strong></p>
        <h3>XML
</h3>
        <p>
"If you're dealing with data that's originated from or destined for an XML file,
XmlConvert (the System.Xml namespace) provides the most suitable methods for formatting
and parsing. The methods in XmlConvert handle the nuances of XML formatting without
needing special format strings." - <strong>C# 3.0 in a Nutshell</strong></p>
        <h3>Iterators
</h3>
        <p>
"The compiler, upon parsing the yield return statement, writes 'behind the scenes,'
a hidden nested enumerator class, and then refactors GetEnumerator to instantiate
and return that class. Iterators are powerful and simple" - <strong>C# 3.0 in
a Nutshell</strong></p>
        <h3>Hash Tables
</h3>
        <p>
"Its underlying hashtable works by converting each element' key into an integer
hashcode - a pseudo unique value - and then applying an algorithm to convert the hashcode
into a hash key. This hash key is used internally to determine which 'bucket' an entry
belongs to. If the bucket contains more than one value, a linear search is performed
on the bucket. A hashtable typically starts out maintaining a 1:1 ration of buckets
to values, meaning that each bucket contains only one value. However, as more items
are added to the hashtable, the load factor dynamically increases, in a manner designed
to optimize insertion and retrieval performance as well as memory requirements."
- C# 3.0 in a Nutshell
</p>
        <h3>Serialization
</h3>
        <p>
"The data contract serializer is the newest and the most versatile of the three
serializatoin engines and is used by WCF. The serializer is particularly strong in
two scenarios:
</p>
        <ul>
          <li>
When exchanging information through standards-compliant messaging protocols 
</li>
          <li>
When you need high-version tolerance plus the option of preserving object references." 
</li>
        </ul>
        <p>
C# 3.0 in a Nutshell
</p>
        <h3>Threading
</h3>
        <p>
"A Mutex is like a C# lock, but it can work across multiple processes. In other
words, Mutex can be computer-wide as well as application-wide" - C# 3.0 in a
Nutshell
</p>
        <p>
"A Semaphore is like a nightclub: it has a certain capacity, enforced by a bouncer.
Once it's full, no more people can enter and a queue build up outside. Then, for each
person that leaves, one person enters from the head of the queue." - C# 3.0 in
a Nutshell
</p>
        <p>
"The Thread class provides GetData and SetData methods for storing nontransient
isolated data in 'slots' whose values persist between method calls." - C# 3.0
in a Nutshell
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=45cf5343-1845-4ebe-bf63-8b5cb93550af" />
      </body>
      <title>Sharpening My C</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,45cf5343-1845-4ebe-bf63-8b5cb93550af.aspx</guid>
      <link>http://mokhan.ca/blog/2008/03/15/Sharpening+My+C.aspx</link>
      <pubDate>Sat, 15 Mar 2008 20:35:43 GMT</pubDate>
      <description>&lt;p&gt;
I recently finished reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/01AYLg-qlrL.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;C# 3.0 in a Nutshell: A Desktop Quick Reference (In a Nutshell (O'Reilly))&lt;/b&gt; 
&lt;br /&gt;
by Joseph Albahari, Ben Albahari 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596527578%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596527578%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
My desire to read this book was to understand what new language features C# 3.0 brings
to the table. This book started to explain the C# language right from the very beginning
up until now. So some of it was a great refresher and some of it was quite boring.
It not only covers the new language features but covers several areas of the framework
class libraries and new lib's that came with the .NET 3.5 stack. 
&lt;/p&gt;
&lt;p&gt;
I was hoping to find my coverage on the new language features to see different usages
for things like extension methods and lambda's to try to get a sense for what I like
and don't like. So far I'm not really a fan of the new query comprehension syntax.
It's to SQL-ish for me... I prefer working directly against methods. But I might have
to give it some time... enough ranting here's some of the things I've learned.
&lt;/p&gt;
&lt;h3&gt;Lambda Expressions
&lt;/h3&gt;
&lt;p&gt;
There's tonnes, and tonnes of discussion on this topic right now. I love how it's
so much cleaner, and less verbose then anonymous delegates, but I see potential room
for abuse. IMHO seeing lambda's tossed around all over your code base is no better
then over using anonymous delegates. I love the new ideas that lambda's bring though...
&lt;/p&gt;
&lt;p&gt;
&amp;quot;A lambda expression is an unnamed method written in place of a delegate instance.
The compiler immediately converts the lambda expression to either:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
A delegate instance. 
&lt;/li&gt;
&lt;li&gt;
An expression tree, of type Expression&amp;lt;T&amp;gt;, representing the code inside the
lambda expression in a traversable object model. This allows the lambda expression
to be interpreted later at runtime...&amp;quot; - &lt;strong&gt;C# 3.0 in a Nutshell&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I love the idea of building up an expression tree of delegates that chain together
to solve an equation. One of the ideas I'm working on is understanding how to leverage
an expression tree of lambdas to solve trivial mathematical equations. Then possible
traversing through the structure with a visitor to build out a display friendly version
of the equation.
&lt;/p&gt;
&lt;h3&gt;WPF
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;The benefits of WPF are as follows:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
It supports sophisticated graphics, such as arbitrary transformations, 3D rendering,
and true transparency. 
&lt;/li&gt;
&lt;li&gt;
Its primary measurement unit is not pixel-based, so applications display correctly
in any DPI 
&lt;/li&gt;
&lt;li&gt;
It has extensive dynamic layout support, which means you can localize any application
without danger of elements overlapping. 
&lt;/li&gt;
&lt;li&gt;
Rendering uses DirectX and is fast, taking good advantage of graphics hardware acceleration. 
&lt;/li&gt;
&lt;li&gt;
User interfaces can be described declaratively in XAML files that can be maintained
independently of the &amp;quot;code-behind&amp;quot; files - this helps to separate appearance
from functionality.&amp;quot; - &lt;strong&gt;C# 3.0 in a Nutshell&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;WCF
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;WCF is the communication infrastructure new to Framework 3.0. WCF is flexible
and configurable enough to make both of its predecessors - Remoting and (.ASMX) Web
Services - mostly redundant.&amp;quot; - &lt;strong&gt;C# 3.0 in a Nutshell&lt;/strong&gt;
&lt;/p&gt;
&lt;h3&gt;XML
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;If you're dealing with data that's originated from or destined for an XML file,
XmlConvert (the System.Xml namespace) provides the most suitable methods for formatting
and parsing. The methods in XmlConvert handle the nuances of XML formatting without
needing special format strings.&amp;quot; - &lt;strong&gt;C# 3.0 in a Nutshell&lt;/strong&gt;
&lt;/p&gt;
&lt;h3&gt;Iterators
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;The compiler, upon parsing the yield return statement, writes 'behind the scenes,'
a hidden nested enumerator class, and then refactors GetEnumerator to instantiate
and return that class. Iterators are powerful and simple&amp;quot; - &lt;strong&gt;C# 3.0 in
a Nutshell&lt;/strong&gt;
&lt;/p&gt;
&lt;h3&gt;Hash Tables
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;Its underlying hashtable works by converting each element' key into an integer
hashcode - a pseudo unique value - and then applying an algorithm to convert the hashcode
into a hash key. This hash key is used internally to determine which 'bucket' an entry
belongs to. If the bucket contains more than one value, a linear search is performed
on the bucket. A hashtable typically starts out maintaining a 1:1 ration of buckets
to values, meaning that each bucket contains only one value. However, as more items
are added to the hashtable, the load factor dynamically increases, in a manner designed
to optimize insertion and retrieval performance as well as memory requirements.&amp;quot;
- C# 3.0 in a Nutshell
&lt;/p&gt;
&lt;h3&gt;Serialization
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;The data contract serializer is the newest and the most versatile of the three
serializatoin engines and is used by WCF. The serializer is particularly strong in
two scenarios:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
When exchanging information through standards-compliant messaging protocols 
&lt;/li&gt;
&lt;li&gt;
When you need high-version tolerance plus the option of preserving object references.&amp;quot; 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
C# 3.0 in a Nutshell
&lt;/p&gt;
&lt;h3&gt;Threading
&lt;/h3&gt;
&lt;p&gt;
&amp;quot;A Mutex is like a C# lock, but it can work across multiple processes. In other
words, Mutex can be computer-wide as well as application-wide&amp;quot; - C# 3.0 in a
Nutshell
&lt;/p&gt;
&lt;p&gt;
&amp;quot;A Semaphore is like a nightclub: it has a certain capacity, enforced by a bouncer.
Once it's full, no more people can enter and a queue build up outside. Then, for each
person that leaves, one person enters from the head of the queue.&amp;quot; - C# 3.0 in
a Nutshell
&lt;/p&gt;
&lt;p&gt;
&amp;quot;The Thread class provides GetData and SetData methods for storing nontransient
isolated data in 'slots' whose values persist between method calls.&amp;quot; - C# 3.0
in a Nutshell
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=45cf5343-1845-4ebe-bf63-8b5cb93550af" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=447a7c16-3e7f-419d-929b-845bc03b4742</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,447a7c16-3e7f-419d-929b-845bc03b4742.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just finished reading...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/11YWFW85S5L.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley
Professional Computing Series)</b>
                  <br />
by Erich Gamma, Richard Helm, Ralph Johnson, John M. Vlissides 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201633612%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201633612%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
It's about time I read this book... This catalog contains 23 patterns with examples
in C++. I enjoyed reading this book. I found at times that my mind started to drift
off, but then there were moments when I would forget where I was and miss my bus stop.
(Ok one moment!)
</p>
        <p>
I enjoyed reading the discussion on OO more then anything else in this book. The examples
are a little dated but for it's time the catalog is awesome. Although I've been wanting
to read this book for a while I preferred "Head First Design Patterns",
mostly because it was easy to read. (I call it the comic book for dev's)
</p>
        <p>
As usual, here are some quotes from the book that I really enjoyed.
</p>
        <p>
"When an abstraction can have one of several possible implementations, the usual
way to accommodate them is to use inheritance. An abstract class defines the interface
to the abstraction, and concrete subclasses implement it in different ways. But this
approach isn't always flexible enough. <strong>Inheritance binds an implementation
to the abstraction permanently, which makes it difficult to modify, extend and reuse
abstractions and implementations independently.</strong>"
</p>
        <p>
"Studies of expert programmers for conventional languages have shown that knowledge
and experience isn't organized simply around syntax but in larger conceptual structures
such as <strong>algorithms, data structures and idioms, and plans for fulfilling a
particular goal</strong>. Designers probably don't think about the notation they're
using for recording the design as much as they try to match the current design situation
against plans, algorithms, data structures, and idioms they have learned in the past."
</p>
        <p>
"These design patterns can also make you a better designer. They provide solutions
to common problems. If you work with object-oriented systems long enough, you'll probably
learn these design patters on your own. But reading the book will help you learn them
much faster. <strong>Learning these patterns will help a novice act more like an expert.</strong>"
</p>
        <p>
"To continue to evolve, the software must be reorganized in a process known as
refactoring. This is the phase in which frameworks often emerge. Refactoring involves
tearing apart classes into special- and general-purpose components, moving operations
up or down the class hierarchy, and rationalizing the interfaces of classes. This
consolidation phase produces many new kinds of objects, often by decomposing existing
objects and <strong>using object composition instead of inheritance</strong>. Hence
black-box reuse replaces white-box reuse. The continual need to satisfy more requirements
along with the need for more reuse propels object-oriented software through repeated
phases of expansion and consolidation - expansion as new requirements are satisfied,
and consolidation as the software becomes more general."
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=447a7c16-3e7f-419d-929b-845bc03b4742" />
      </body>
      <title>Hangin' Out With The Gang Of Four</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,447a7c16-3e7f-419d-929b-845bc03b4742.aspx</guid>
      <link>http://mokhan.ca/blog/2008/02/24/Hangin+Out+With+The+Gang+Of+Four.aspx</link>
      <pubDate>Sun, 24 Feb 2008 02:35:34 GMT</pubDate>
      <description>&lt;p&gt;
I just finished reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/11YWFW85S5L.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley
Professional Computing Series)&lt;/b&gt; 
&lt;br /&gt;
by Erich Gamma, Richard Helm, Ralph Johnson, John M. Vlissides 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201633612%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201633612%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
It's about time I read this book... This catalog contains 23 patterns with examples
in C++. I enjoyed reading this book. I found at times that my mind started to drift
off, but then there were moments when I would forget where I was and miss my bus stop.
(Ok one moment!)
&lt;/p&gt;
&lt;p&gt;
I enjoyed reading the discussion on OO more then anything else in this book. The examples
are a little dated but for it's time the catalog is awesome. Although I've been wanting
to read this book for a while I preferred &amp;quot;Head First Design Patterns&amp;quot;,
mostly because it was easy to read. (I call it the comic book for dev's)
&lt;/p&gt;
&lt;p&gt;
As usual, here are some quotes from the book that I really enjoyed.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;When an abstraction can have one of several possible implementations, the usual
way to accommodate them is to use inheritance. An abstract class defines the interface
to the abstraction, and concrete subclasses implement it in different ways. But this
approach isn't always flexible enough. &lt;strong&gt;Inheritance binds an implementation
to the abstraction permanently, which makes it difficult to modify, extend and reuse
abstractions and implementations independently.&lt;/strong&gt;&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Studies of expert programmers for conventional languages have shown that knowledge
and experience isn't organized simply around syntax but in larger conceptual structures
such as &lt;strong&gt;algorithms, data structures and idioms, and plans for fulfilling a
particular goal&lt;/strong&gt;. Designers probably don't think about the notation they're
using for recording the design as much as they try to match the current design situation
against plans, algorithms, data structures, and idioms they have learned in the past.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;These design patterns can also make you a better designer. They provide solutions
to common problems. If you work with object-oriented systems long enough, you'll probably
learn these design patters on your own. But reading the book will help you learn them
much faster. &lt;strong&gt;Learning these patterns will help a novice act more like an expert.&lt;/strong&gt;&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;To continue to evolve, the software must be reorganized in a process known as
refactoring. This is the phase in which frameworks often emerge. Refactoring involves
tearing apart classes into special- and general-purpose components, moving operations
up or down the class hierarchy, and rationalizing the interfaces of classes. This
consolidation phase produces many new kinds of objects, often by decomposing existing
objects and &lt;strong&gt;using object composition instead of inheritance&lt;/strong&gt;. Hence
black-box reuse replaces white-box reuse. The continual need to satisfy more requirements
along with the need for more reuse propels object-oriented software through repeated
phases of expansion and consolidation - expansion as new requirements are satisfied,
and consolidation as the software becomes more general.&amp;quot;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=447a7c16-3e7f-419d-929b-845bc03b4742" /&gt;</description>
      <category>Books</category>
      <category>Design Patterns</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=dacbd445-fb54-4cc9-aafa-8dfbb59b5539</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,dacbd445-fb54-4cc9-aafa-8dfbb59b5539.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've got a beef with enums. When I see them, I cringe... which is quite different
from my days in C, where I couldn't live without enums and structs. That's another
story...
</p>
        <blockquote>
          <p>
"Flyweight: Use sharing to support large numbers of fine-grained objects efficiently"
- Design Patterns
</p>
        </blockquote>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/11YWFW85S5L.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley
Professional Computing Series)</b>
                  <br />
by Erich Gamma, Richard Helm, Ralph Johnson, John M. Vlissides 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201633612%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201633612%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
Why do some of us quickly jump to enums? In procedural languages it makes sense. It's
giving a type code a human readable meaning. So instead of having to stare at type
code 1, everywhere you can use State.Acknowledgement, which is a lot easier to understand
... what does 1 mean again?
</p>
        <p>
But in an OO language, I feel dirty when I see enums. The argument of using it for
bitwise operations and the Flags attribute is weak. Create a composite!
</p>
        <pre class="code">    [<span style="color: rgb(43,145,175)">Flags</span>] <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">enum</span><span style="color: rgb(43,145,175)">Digits</span> {
Zero = 0x00, One = 0x01, Two = 0x02, Three = 0x03, Four = 0x04, Five = 0x05, Six =
0x06, Seven = 0x07, Eight = 0x08, Nine = 0x09 }</pre>
        <pre class="code">    [<span style="color: rgb(43,145,175)">Test</span>] <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Should_be_equal_to_2_digits()
{ <span style="color: rgb(43,145,175)">Digits</span> digits = <span style="color: rgb(43,145,175)">Digits</span>.Six
| <span style="color: rgb(43,145,175)">Digits</span>.One; <span style="color: rgb(43,145,175)">Assert</span>.IsTrue( <span style="color: rgb(43,145,175)">Digits</span>.Six
== (digits &amp; <span style="color: rgb(43,145,175)">Digits</span>.Six) ); <span style="color: rgb(43,145,175)">Assert</span>.IsTrue( <span style="color: rgb(43,145,175)">Digits</span>.One
== (digits &amp; <span style="color: rgb(43,145,175)">Digits</span>.One) ); }</pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>Weak... do you really want to use
a bitwise &amp; to check if a certain digit is enabled. I don't. I'm going to use
the following 2 tests to squash the enum into a first class component, with some smarts
to it.
</p>
        <pre class="code">        [<span style="color: rgb(43,145,175)">Test</span>] <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> should_be_able_to_add_a_single_digit()
{ <span style="color: rgb(43,145,175)">INumberBuilder</span> builder = CreateSUT(
); builder.Add( <span style="color: rgb(43,145,175)">Digits</span>.One ); <span style="color: rgb(43,145,175)">Assert</span>.AreEqual( <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Number</span>(
1 ), builder.Build( ) ); } [<span style="color: rgb(43,145,175)">Test</span>] <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> should_be_able_to_form_a_number_with_more_than_one_digit()
{ <span style="color: rgb(43,145,175)">INumberBuilder</span> builder = CreateSUT(
); builder.Add( <span style="color: rgb(43,145,175)">Digits</span>.One ); builder.Add( <span style="color: rgb(43,145,175)">Digits</span>.Nine
); <span style="color: rgb(43,145,175)">Assert</span>.AreEqual( <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Number</span>(
19 ), builder.Build( ) ); }</pre>
        <p>
My current NumberBuilder implementation looks like this (it sucks but it works):
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">NumberBuilder</span> : <span style="color: rgb(43,145,175)">INumberBuilder</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Add( <span style="color: rgb(43,145,175)">Digits</span> digit
) { numberBeingBuilt += <span style="color: rgb(43,145,175)">Convert</span>.ToString( <span style="color: rgb(43,145,175)">Convert</span>.ToInt32(
digit ) ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(43,145,175)">INumber</span> Build()
{ <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Number</span>( <span style="color: rgb(43,145,175)">Convert</span>.ToInt32(
numberBeingBuilt ) ); } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">string</span> numberBeingBuilt;
}</pre>
        <p>
I'm going to start off by creating some Flyweights. 
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">Digits</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDigit</span> Eight
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Digit</span>(
8 ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDigit</span> Five
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Digit</span>(
5 ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDigit</span> Four
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Digit</span>(
4 ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDigit</span> Nine
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Digit</span>(
9 ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDigit</span> One
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Digit</span>(
1 ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDigit</span> Seven
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Digit</span>(
7 ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDigit</span> Six
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Digit</span>(
6 ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDigit</span> Three
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Digit</span>(
3 ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDigit</span> Two
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Digit</span>(
2 ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDigit</span> Zero
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Digit</span>(
0 ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">class</span><span style="color: rgb(43,145,175)">Digit</span> : <span style="color: rgb(43,145,175)">IDigit</span> { <span style="color: rgb(0,0,255)">public</span> Digit( <span style="color: rgb(0,0,255)">int</span> digitToRepresent
) { _digitToRepresent = digitToRepresent; } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">override</span><span style="color: rgb(0,0,255)">string</span> ToString()
{ <span style="color: rgb(0,0,255)">return</span> _digitToRepresent.ToString( ); } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(0,0,255)">int</span> _digitToRepresent;
} }</pre>
        <p>
My compiler is telling me that the Add method on my builder currently accepts a parameter
of type "Digits", so I'm going to change the signature to accept a parameter
of type IDigit.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">interface</span>
          <span style="color: rgb(43,145,175)">INumberBuilder</span> { <span style="color: rgb(0,0,255)">void</span> Add( <span style="color: rgb(43,145,175)">Digits</span> digit
); <span style="color: rgb(43,145,175)">INumber</span> Build(); }</pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>To...
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">interface</span>
          <span style="color: rgb(43,145,175)">INumberBuilder</span> { <span style="color: rgb(0,0,255)">void</span> Add( <span style="color: rgb(43,145,175)">IDigit</span> digit
); <span style="color: rgb(43,145,175)">INumber</span> Build(); }</pre>
        <p>
Let's update the NumberBuilder implementation to:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">NumberBuilder</span> : <span style="color: rgb(43,145,175)">INumberBuilder</span> { <span style="color: rgb(0,0,255)">public</span> NumberBuilder()
{ _digitsOfNumberBeingBuilt = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">List</span>&lt; <span style="color: rgb(43,145,175)">IDigit</span> &gt;(
); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Add( <span style="color: rgb(43,145,175)">IDigit</span> digit
) { _digitsOfNumberBeingBuilt.Add( digit ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(43,145,175)">INumber</span> Build()
{ <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Number</span>(
CreateIntegerFrom( _digitsOfNumberBeingBuilt ) ); } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">int</span> CreateIntegerFrom( <span style="color: rgb(43,145,175)">IEnumerable</span>&lt; <span style="color: rgb(43,145,175)">IDigit</span> &gt;
digitsOfNumberBeingBuilt ) { <span style="color: rgb(43,145,175)">StringBuilder</span> builder
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StringBuilder</span>(
); <span style="color: rgb(0,0,255)">foreach</span> ( <span style="color: rgb(43,145,175)">IDigit</span> digit <span style="color: rgb(0,0,255)">in</span> digitsOfNumberBeingBuilt
) { builder.Append( digit ); } <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(43,145,175)">Convert</span>.ToInt32(
builder.ToString( ) ); } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(43,145,175)">IList</span>&lt; <span style="color: rgb(43,145,175)">IDigit</span> &gt;
_digitsOfNumberBeingBuilt; }</pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>I run the tests and they pass, sweet.
But I'm not happy with the current implementation, so I look for other potential refactorings.
I decide to forward the digit to append right to the number, the number can take care
of how to append the digit, rather then having the builder doing so. The builder now
looks like:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">NumberBuilder</span> : <span style="color: rgb(43,145,175)">INumberBuilder</span> { <span style="color: rgb(0,0,255)">public</span> NumberBuilder()
{ _numberBeingBuilt = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Number</span>(
0 ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Append( <span style="color: rgb(43,145,175)">IDigit</span> digit
) { _numberBeingBuilt = _numberBeingBuilt.Append( digit ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(43,145,175)">INumber</span> Build()
{ <span style="color: rgb(0,0,255)">return</span> _numberBeingBuilt; } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(43,145,175)">INumber</span> _numberBeingBuilt;
}</pre>
        <p>
And Number looks like:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">Number</span> : <span style="color: rgb(43,145,175)">INumber</span>, <span style="color: rgb(43,145,175)">IEquatable</span>&lt; <span style="color: rgb(43,145,175)">Number</span> &gt;
{ <span style="color: rgb(0,0,255)">public</span> Number() : <span style="color: rgb(0,0,255)">this</span>(
0 ) {} <span style="color: rgb(0,0,255)">public</span> Number( <span style="color: rgb(0,0,255)">int</span> numberToRepresent
) { _numberToRepresent = numberToRepresent; } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(43,145,175)">INumber</span> Append( <span style="color: rgb(43,145,175)">IDigit</span> digit
) { <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Number</span>(
( _numberToRepresent*10 ) + digit.Value( ) ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">bool</span> Equals( <span style="color: rgb(43,145,175)">Number</span> number
) { <span style="color: rgb(0,0,255)">if</span> ( number == <span style="color: rgb(0,0,255)">null</span> )
{ <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">false</span>;
} <span style="color: rgb(0,0,255)">return</span> _numberToRepresent == number._numberToRepresent;
} <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">override</span><span style="color: rgb(0,0,255)">string</span> ToString()
{ <span style="color: rgb(0,0,255)">return</span> _numberToRepresent.ToString( );
} <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">override</span><span style="color: rgb(0,0,255)">bool</span> Equals( <span style="color: rgb(0,0,255)">object</span> obj
) { <span style="color: rgb(0,0,255)">if</span> ( ReferenceEquals( <span style="color: rgb(0,0,255)">this</span>,
obj ) ) { <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">true</span>;
} <span style="color: rgb(0,0,255)">return</span> Equals( obj <span style="color: rgb(0,0,255)">as</span><span style="color: rgb(43,145,175)">Number</span> );
} <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">override</span><span style="color: rgb(0,0,255)">int</span> GetHashCode()
{ <span style="color: rgb(0,0,255)">return</span> _numberToRepresent; } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(0,0,255)">int</span> _numberToRepresent;
}</pre>
        <p>
To wrap this up, Number aggregates digits, the enum got dropped and was replaced by
a class. There's still more refactorings that can occur, but the point is that a full
blown component is much easier to extend then an enum... 
</p>
        <p>
For more info check out "Replace Type Code with Class" from...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/018JK26EM8L.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Refactoring: Improving the Design of Existing Code (The Addison-Wesley Object Technology
Series)</b>
                  <br />
by Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201485672%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201485672%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
          <a href="http://11011.net/software/vspaste"> </a>Soure:
</p>
        <ul>
          <li>
            <a href="http://mokhan.ca/blog/content/binary/drop.the.enums/DigitsWithEnum.txt">Before</a>
          </li>
          <li>
            <a href="http://mokhan.ca/blog/content/binary/drop.the.enums/DigitsWithFlyweights.txt">After</a>
          </li>
        </ul>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=dacbd445-fb54-4cc9-aafa-8dfbb59b5539" />
      </body>
      <title>Replace Enum With Flyweights</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,dacbd445-fb54-4cc9-aafa-8dfbb59b5539.aspx</guid>
      <link>http://mokhan.ca/blog/2008/02/23/Replace+Enum+With+Flyweights.aspx</link>
      <pubDate>Sat, 23 Feb 2008 18:08:21 GMT</pubDate>
      <description>&lt;p&gt;
I've got a beef with enums. When I see them, I cringe... which is quite different
from my days in C, where I couldn't live without enums and structs. That's another
story...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;Flyweight: Use sharing to support large numbers of fine-grained objects efficiently&amp;quot;
- Design Patterns
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/11YWFW85S5L.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley
Professional Computing Series)&lt;/b&gt; 
&lt;br /&gt;
by Erich Gamma, Richard Helm, Ralph Johnson, John M. Vlissides 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201633612%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201633612%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
Why do some of us quickly jump to enums? In procedural languages it makes sense. It's
giving a type code a human readable meaning. So instead of having to stare at type
code 1, everywhere you can use State.Acknowledgement, which is a lot easier to understand
... what does 1 mean again?
&lt;/p&gt;
&lt;p&gt;
But in an OO language, I feel dirty when I see enums. The argument of using it for
bitwise operations and the Flags attribute is weak. Create a composite!
&lt;/p&gt;
&lt;pre class="code"&gt;    [&lt;span style="color: rgb(43,145,175)"&gt;Flags&lt;/span&gt;] &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;enum&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt; {
Zero = 0x00, One = 0x01, Two = 0x02, Three = 0x03, Four = 0x04, Five = 0x05, Six =
0x06, Seven = 0x07, Eight = 0x08, Nine = 0x09 }&lt;/pre&gt;
&lt;pre class="code"&gt;    [&lt;span style="color: rgb(43,145,175)"&gt;Test&lt;/span&gt;] &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Should_be_equal_to_2_digits()
{ &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt; digits = &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt;.Six
| &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt;.One; &lt;span style="color: rgb(43,145,175)"&gt;Assert&lt;/span&gt;.IsTrue( &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt;.Six
== (digits &amp;amp; &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt;.Six) ); &lt;span style="color: rgb(43,145,175)"&gt;Assert&lt;/span&gt;.IsTrue( &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt;.One
== (digits &amp;amp; &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt;.One) ); }&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Weak... do you really want to use
a bitwise &amp;amp; to check if a certain digit is enabled. I don't. I'm going to use
the following 2 tests to squash the enum into a first class component, with some smarts
to it.
&lt;/p&gt;
&lt;pre class="code"&gt;        [&lt;span style="color: rgb(43,145,175)"&gt;Test&lt;/span&gt;] &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; should_be_able_to_add_a_single_digit()
{ &lt;span style="color: rgb(43,145,175)"&gt;INumberBuilder&lt;/span&gt; builder = CreateSUT(
); builder.Add( &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt;.One ); &lt;span style="color: rgb(43,145,175)"&gt;Assert&lt;/span&gt;.AreEqual( &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Number&lt;/span&gt;(
1 ), builder.Build( ) ); } [&lt;span style="color: rgb(43,145,175)"&gt;Test&lt;/span&gt;] &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; should_be_able_to_form_a_number_with_more_than_one_digit()
{ &lt;span style="color: rgb(43,145,175)"&gt;INumberBuilder&lt;/span&gt; builder = CreateSUT(
); builder.Add( &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt;.One ); builder.Add( &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt;.Nine
); &lt;span style="color: rgb(43,145,175)"&gt;Assert&lt;/span&gt;.AreEqual( &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Number&lt;/span&gt;(
19 ), builder.Build( ) ); }&lt;/pre&gt;
&lt;p&gt;
My current NumberBuilder implementation looks like this (it sucks but it works):
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;NumberBuilder&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;INumberBuilder&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Add( &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt; digit
) { numberBeingBuilt += &lt;span style="color: rgb(43,145,175)"&gt;Convert&lt;/span&gt;.ToString( &lt;span style="color: rgb(43,145,175)"&gt;Convert&lt;/span&gt;.ToInt32(
digit ) ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;INumber&lt;/span&gt; Build()
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Number&lt;/span&gt;( &lt;span style="color: rgb(43,145,175)"&gt;Convert&lt;/span&gt;.ToInt32(
numberBeingBuilt ) ); } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; numberBeingBuilt;
}&lt;/pre&gt;
&lt;p&gt;
I'm going to start off by creating some Flyweights. 
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; Eight
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt;(
8 ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; Five
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt;(
5 ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; Four
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt;(
4 ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; Nine
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt;(
9 ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; One
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt;(
1 ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; Seven
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt;(
7 ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; Six
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt;(
6 ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; Three
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt;(
3 ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; Two
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt;(
2 ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; Zero
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt;(
0 ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Digit&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; Digit( &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; digitToRepresent
) { _digitToRepresent = digitToRepresent; } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; ToString()
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; _digitToRepresent.ToString( ); } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; _digitToRepresent;
} }&lt;/pre&gt;
&lt;p&gt;
My compiler is telling me that the Add method on my builder currently accepts a parameter
of type &amp;quot;Digits&amp;quot;, so I'm going to change the signature to accept a parameter
of type IDigit.
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;INumberBuilder&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Add( &lt;span style="color: rgb(43,145,175)"&gt;Digits&lt;/span&gt; digit
); &lt;span style="color: rgb(43,145,175)"&gt;INumber&lt;/span&gt; Build(); }&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;To...
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;INumberBuilder&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Add( &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; digit
); &lt;span style="color: rgb(43,145,175)"&gt;INumber&lt;/span&gt; Build(); }&lt;/pre&gt;
&lt;p&gt;
Let's update the NumberBuilder implementation to:
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;NumberBuilder&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;INumberBuilder&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; NumberBuilder()
{ _digitsOfNumberBeingBuilt = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;List&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; &amp;gt;(
); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Add( &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; digit
) { _digitsOfNumberBeingBuilt.Add( digit ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;INumber&lt;/span&gt; Build()
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Number&lt;/span&gt;(
CreateIntegerFrom( _digitsOfNumberBeingBuilt ) ); } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; CreateIntegerFrom( &lt;span style="color: rgb(43,145,175)"&gt;IEnumerable&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; &amp;gt;
digitsOfNumberBeingBuilt ) { &lt;span style="color: rgb(43,145,175)"&gt;StringBuilder&lt;/span&gt; builder
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StringBuilder&lt;/span&gt;(
); &lt;span style="color: rgb(0,0,255)"&gt;foreach&lt;/span&gt; ( &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; digit &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; digitsOfNumberBeingBuilt
) { builder.Append( digit ); } &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Convert&lt;/span&gt;.ToInt32(
builder.ToString( ) ); } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IList&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; &amp;gt;
_digitsOfNumberBeingBuilt; }&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;I run the tests and they pass, sweet.
But I'm not happy with the current implementation, so I look for other potential refactorings.
I decide to forward the digit to append right to the number, the number can take care
of how to append the digit, rather then having the builder doing so. The builder now
looks like:
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;NumberBuilder&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;INumberBuilder&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; NumberBuilder()
{ _numberBeingBuilt = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Number&lt;/span&gt;(
0 ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Append( &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; digit
) { _numberBeingBuilt = _numberBeingBuilt.Append( digit ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;INumber&lt;/span&gt; Build()
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; _numberBeingBuilt; } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;INumber&lt;/span&gt; _numberBeingBuilt;
}&lt;/pre&gt;
&lt;p&gt;
And Number looks like:
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Number&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;INumber&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;IEquatable&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;Number&lt;/span&gt; &amp;gt;
{ &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; Number() : &lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;(
0 ) {} &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; Number( &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; numberToRepresent
) { _numberToRepresent = numberToRepresent; } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;INumber&lt;/span&gt; Append( &lt;span style="color: rgb(43,145,175)"&gt;IDigit&lt;/span&gt; digit
) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Number&lt;/span&gt;(
( _numberToRepresent*10 ) + digit.Value( ) ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;bool&lt;/span&gt; Equals( &lt;span style="color: rgb(43,145,175)"&gt;Number&lt;/span&gt; number
) { &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; ( number == &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt; )
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;false&lt;/span&gt;;
} &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; _numberToRepresent == number._numberToRepresent;
} &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; ToString()
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; _numberToRepresent.ToString( );
} &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;bool&lt;/span&gt; Equals( &lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt; obj
) { &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; ( ReferenceEquals( &lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;,
obj ) ) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;true&lt;/span&gt;;
} &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; Equals( obj &lt;span style="color: rgb(0,0,255)"&gt;as&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Number&lt;/span&gt; );
} &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; GetHashCode()
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; _numberToRepresent; } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; _numberToRepresent;
}&lt;/pre&gt;
&lt;p&gt;
To wrap this up, Number aggregates digits, the enum got dropped and was replaced by
a class. There's still more refactorings that can occur, but the point is that a full
blown component is much easier to extend then an enum... 
&lt;/p&gt;
&lt;p&gt;
For more info check out &amp;quot;Replace Type Code with Class&amp;quot; from...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/018JK26EM8L.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Refactoring: Improving the Design of Existing Code (The Addison-Wesley Object Technology
Series)&lt;/b&gt; 
&lt;br /&gt;
by Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201485672%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201485672%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&amp;#160;&lt;/a&gt;Soure:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://mokhan.ca/blog/content/binary/drop.the.enums/DigitsWithEnum.txt"&gt;Before&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://mokhan.ca/blog/content/binary/drop.the.enums/DigitsWithFlyweights.txt"&gt;After&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=dacbd445-fb54-4cc9-aafa-8dfbb59b5539" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
      <category>Design Patterns</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=edc853ba-79fe-40fc-99be-07a5e6c5b0c6</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,edc853ba-79fe-40fc-99be-07a5e6c5b0c6.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This month I read...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/018JK26EM8L.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Refactoring: Improving the Design of Existing Code (The Addison-Wesley Object Technology
Series)</b>
                  <br />
by Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201485672%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201485672%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
This book is awesome and a must read for anyone who enjoys the art of refactoring
as much as I do. The examples are crystal clear and the way the refactorings are done
step by step makes it so much more understandable.
</p>
        <p>
Here are a few excerpts that I enjoyed from this book.
</p>
        <p>
"The problem with copying and pasting code comes when you have to change it later.
If you are writing a program that you don't expect to change, then cut and paste is
fine. If the program is long lived and likely to change, then cut and paste is a menace."
</p>
        <p>
I've got to agree and disagree with the above statement. I think anytime you find
yourself copying and pasting is a clear sign of duplication which should be improved.
Removing duplication should be something we all strive for, and remember that inheritance
is not the only way to remove duplication. Proper object composition, delegation and
generics are all great ways to remove duplicate code. 
</p>
        <p>
Replace conditional with Polymorphism has to be by far one of my favorite refactorings.
If you're seeing if-else statements scattered throughout your code base that's a smell.
Switch's are no better... (booo switches...)
</p>
        <p>
"Is renaming worth the effort? Absolutely. Good code  should communicate
what it is doing clearly, and variable names are a key to clear code. Never be afraid
to change the names of things to improve clarity." 
</p>
        <p>
Amen, brother! Thank goodness for tools like Resharper and Rhino.Mocks. On my current
project we're using NMock2 and I got burned several times doing a Rename Method because
of the string literals used in NMock tests... My advice is just use Rhino Mocks...
please... for my sake!
</p>
        <p>
"You write code that tells the computer what to do, and it responds by doing
exactly what you tell it. In time you close the gap between what you want it to do
and what you tell it to do. Programming in this mode is all about saying exactly what
you want. But there is another use of your source code. Someone will try to read your
code in a few months' time to make some changes. We easily forget that extra user
of the code, yet that user is actually the most important."
</p>
        <p>
"The first time you do something, you just do it. The second time you do something
similar, you wince at the duplication, but you do the duplicate thing anyway. The
third time you do something similar, you refactor."
</p>
        <p>
I often heard the term "smell" used as a way to describe something funky
in a code base or team but I had no idea where the term came from... until know!
</p>
        <blockquote>
          <p>
"If it stinks, change it." - Gradma Beck, discussing child-rearing philosophy
</p>
        </blockquote>
        <p>
The chapter on code smells is awesome, it's offers a catalog of code smells like:
</p>
        <ul>
          <li>
Duplicate Code 
</li>
          <li>
Long Methods 
</li>
          <li>
Large Classes 
</li>
          <li>
Long Parameter Lists 
</li>
          <li>
Divergent Changes 
</li>
          <li>
Shotgun Surgery 
</li>
          <li>
Feature Envy 
</li>
          <li>
Data Clumps 
</li>
          <li>
Primitive Obsession 
</li>
          <li>
Switch Statements 
</li>
          <li>
Parallel Inheritance Hierarchies 
</li>
          <li>
Lazy Class 
</li>
          <li>
Speculative Generality - "Oh, I think we need the ability to do this kind of
thing someday." 
</li>
          <li>
Temporary Fields 
</li>
          <li>
Message Chains 
</li>
          <li>
Middle Man 
</li>
          <li>
Inappropriate Intimacy 
</li>
          <li>
Alternative Classes with Different Interfaces 
</li>
          <li>
Incomplete Library Classes 
</li>
          <li>
Data Classes 
</li>
          <li>
Refused Bequest - "Subclasses get to inherit the methods and data of their parents.
But what if they don't want or need what they are given?" 
</li>
          <li>
Comments 
</li>
        </ul>
        <p>
If you only read one chapter in this book, I suggest Chapter 3. "Bad Smells in
Code". I really like how Resharper uses the same refactoring names as those mentioned
in this book. Anyway's, what are you waiting for go read this book.
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=edc853ba-79fe-40fc-99be-07a5e6c5b0c6" />
      </body>
      <title>Continuous Improvement</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,edc853ba-79fe-40fc-99be-07a5e6c5b0c6.aspx</guid>
      <link>http://mokhan.ca/blog/2008/02/19/Continuous+Improvement.aspx</link>
      <pubDate>Tue, 19 Feb 2008 00:06:47 GMT</pubDate>
      <description>&lt;p&gt;
This month I read...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/018JK26EM8L.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Refactoring: Improving the Design of Existing Code (The Addison-Wesley Object Technology
Series)&lt;/b&gt; 
&lt;br /&gt;
by Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0201485672%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0201485672%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
This book is awesome and a must read for anyone who enjoys the art of refactoring
as much as I do. The examples are crystal clear and the way the refactorings are done
step by step makes it so much more understandable.
&lt;/p&gt;
&lt;p&gt;
Here are a few excerpts that I enjoyed from this book.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;The problem with copying and pasting code comes when you have to change it later.
If you are writing a program that you don't expect to change, then cut and paste is
fine. If the program is long lived and likely to change, then cut and paste is a menace.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
I've got to agree and disagree with the above statement. I think anytime you find
yourself copying and pasting is a clear sign of duplication which should be improved.
Removing duplication should be something we all strive for, and remember that inheritance
is not the only way to remove duplication. Proper object composition, delegation and
generics are all great ways to remove duplicate code. 
&lt;/p&gt;
&lt;p&gt;
Replace conditional with Polymorphism has to be by far one of my favorite refactorings.
If you're seeing if-else statements scattered throughout your code base that's a smell.
Switch's are no better... (booo switches...)
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Is renaming worth the effort? Absolutely. Good code&amp;#160; should communicate
what it is doing clearly, and variable names are a key to clear code. Never be afraid
to change the names of things to improve clarity.&amp;quot; 
&lt;/p&gt;
&lt;p&gt;
Amen, brother! Thank goodness for tools like Resharper and Rhino.Mocks. On my current
project we're using NMock2 and I got burned several times doing a Rename Method because
of the string literals used in NMock tests... My advice is just use Rhino Mocks...
please... for my sake!
&lt;/p&gt;
&lt;p&gt;
&amp;quot;You write code that tells the computer what to do, and it responds by doing
exactly what you tell it. In time you close the gap between what you want it to do
and what you tell it to do. Programming in this mode is all about saying exactly what
you want. But there is another use of your source code. Someone will try to read your
code in a few months' time to make some changes. We easily forget that extra user
of the code, yet that user is actually the most important.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;The first time you do something, you just do it. The second time you do something
similar, you wince at the duplication, but you do the duplicate thing anyway. The
third time you do something similar, you refactor.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
I often heard the term &amp;quot;smell&amp;quot; used as a way to describe something funky
in a code base or team but I had no idea where the term came from... until know!
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;If it stinks, change it.&amp;quot; - Gradma Beck, discussing child-rearing philosophy
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
The chapter on code smells is awesome, it's offers a catalog of code smells like:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Duplicate Code 
&lt;/li&gt;
&lt;li&gt;
Long Methods 
&lt;/li&gt;
&lt;li&gt;
Large Classes 
&lt;/li&gt;
&lt;li&gt;
Long Parameter Lists 
&lt;/li&gt;
&lt;li&gt;
Divergent Changes 
&lt;/li&gt;
&lt;li&gt;
Shotgun Surgery 
&lt;/li&gt;
&lt;li&gt;
Feature Envy 
&lt;/li&gt;
&lt;li&gt;
Data Clumps 
&lt;/li&gt;
&lt;li&gt;
Primitive Obsession 
&lt;/li&gt;
&lt;li&gt;
Switch Statements 
&lt;/li&gt;
&lt;li&gt;
Parallel Inheritance Hierarchies 
&lt;/li&gt;
&lt;li&gt;
Lazy Class 
&lt;/li&gt;
&lt;li&gt;
Speculative Generality - &amp;quot;Oh, I think we need the ability to do this kind of
thing someday.&amp;quot; 
&lt;/li&gt;
&lt;li&gt;
Temporary Fields 
&lt;/li&gt;
&lt;li&gt;
Message Chains 
&lt;/li&gt;
&lt;li&gt;
Middle Man 
&lt;/li&gt;
&lt;li&gt;
Inappropriate Intimacy 
&lt;/li&gt;
&lt;li&gt;
Alternative Classes with Different Interfaces 
&lt;/li&gt;
&lt;li&gt;
Incomplete Library Classes 
&lt;/li&gt;
&lt;li&gt;
Data Classes 
&lt;/li&gt;
&lt;li&gt;
Refused Bequest - &amp;quot;Subclasses get to inherit the methods and data of their parents.
But what if they don't want or need what they are given?&amp;quot; 
&lt;/li&gt;
&lt;li&gt;
Comments 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
If you only read one chapter in this book, I suggest Chapter 3. &amp;quot;Bad Smells in
Code&amp;quot;. I really like how Resharper uses the same refactoring names as those mentioned
in this book. Anyway's, what are you waiting for go read this book.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=edc853ba-79fe-40fc-99be-07a5e6c5b0c6" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=ac7903e5-93c4-49a4-bc20-7612f3968275</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,ac7903e5-93c4-49a4-bc20-7612f3968275.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This month I read...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/01%2B6uIlcW9L.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Hackers and Painters: Big Ideas from the Computer Age</b>
                  <br />
by Paul Graham 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596006624%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596006624%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
This was not what I expected, but then again I wasn't really sure what I expected.
But I liked it, the first chapter kind of caught me off guard, but some of the analogies
and comparisons make a lot of sense. You can tell that Mr. Paul Graham sure is a thinker!
</p>
        <p>
Here are a few excerpts from the book that I found enjoyable:
</p>
        <p>
"Big companies win by sucking less than other big companies."
</p>
        <p>
"You learn to paint mostly by doing it. Ditto for hacking. Most hackers don't
learn to hack by taking college courses in programming. They learn by writing programs
of their own at age thirteen. Even in college classes, you learn to hack mostly by
hacking."
</p>
        <p>
"Maybe it would be good for hackers to act more like painters, and regularly
start over from scratch, instead of continuing to work for years on one project, and
trying to incorporate all their later ideas as revisions."
</p>
        <p>
"If I could get people to remember just one quote about programming, it would
be the one at the beginning of <em>Structure and Interpretation of Computer Programs.</em></p>
        <p>
Programs should be written for people to read, and only incidentally for machines
to execute."
</p>
        <p>
"When you catch bugs early, you also get fewer compound bugs. Compound bugs are
two separate bugs that interact: you trip going downstairs, and when you reach for
the handrail it comes off in your hand."
</p>
        <p>
"Mistakes are natural. Instead of treating them as disasters, make them easy
to acknowledge and easy to fix. Leonardo more or less invented the sketch, as a way
to make drawing bear a greater weight of exploration. Open source software has fewer
bugs because it admits the possibility of bugs."
</p>
        <p>
"Of all tyrannies, a tyranny exercised for the good of its victims may be the
most oppressive. - C.S. Lewis"
</p>
        <p>
"One of my first drawing teachers told me: if you're bored when you're drawing
something, the drawing will look boring."
</p>
        <p>
"Indeed, there is even a saying among painters: 'A painting is never finished.
You just stop working on it.'"
</p>
        <p>
There is so much great content in this book that just provokes thought. I highly encourage
you to go check it out, it's definitely worth reading and re-reading.
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=ac7903e5-93c4-49a4-bc20-7612f3968275" />
      </body>
      <title>Hacking &amp;amp; Painting</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,ac7903e5-93c4-49a4-bc20-7612f3968275.aspx</guid>
      <link>http://mokhan.ca/blog/2008/02/01/Hacking+Amp+Painting.aspx</link>
      <pubDate>Fri, 01 Feb 2008 23:06:01 GMT</pubDate>
      <description>&lt;p&gt;
This month I read...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/01%2B6uIlcW9L.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Hackers and Painters: Big Ideas from the Computer Age&lt;/b&gt; 
&lt;br /&gt;
by Paul Graham 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596006624%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596006624%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
This was not what I expected, but then again I wasn't really sure what I expected.
But I liked it, the first chapter kind of caught me off guard, but some of the analogies
and comparisons make a lot of sense. You can tell that Mr. Paul Graham sure is a thinker!
&lt;/p&gt;
&lt;p&gt;
Here are a few excerpts from the book that I found enjoyable:
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Big companies win by sucking less than other big companies.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;You learn to paint mostly by doing it. Ditto for hacking. Most hackers don't
learn to hack by taking college courses in programming. They learn by writing programs
of their own at age thirteen. Even in college classes, you learn to hack mostly by
hacking.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Maybe it would be good for hackers to act more like painters, and regularly
start over from scratch, instead of continuing to work for years on one project, and
trying to incorporate all their later ideas as revisions.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;If I could get people to remember just one quote about programming, it would
be the one at the beginning of &lt;em&gt;Structure and Interpretation of Computer Programs.&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Programs should be written for people to read, and only incidentally for machines
to execute.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;When you catch bugs early, you also get fewer compound bugs. Compound bugs are
two separate bugs that interact: you trip going downstairs, and when you reach for
the handrail it comes off in your hand.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Mistakes are natural. Instead of treating them as disasters, make them easy
to acknowledge and easy to fix. Leonardo more or less invented the sketch, as a way
to make drawing bear a greater weight of exploration. Open source software has fewer
bugs because it admits the possibility of bugs.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Of all tyrannies, a tyranny exercised for the good of its victims may be the
most oppressive. - C.S. Lewis&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;One of my first drawing teachers told me: if you're bored when you're drawing
something, the drawing will look boring.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Indeed, there is even a saying among painters: 'A painting is never finished.
You just stop working on it.'&amp;quot;
&lt;/p&gt;
&lt;p&gt;
There is so much great content in this book that just provokes thought. I highly encourage
you to go check it out, it's definitely worth reading and re-reading.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=ac7903e5-93c4-49a4-bc20-7612f3968275" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=1c2e3c8c-5c3e-47bd-aaba-9ef398991acf</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,1c2e3c8c-5c3e-47bd-aaba-9ef398991acf.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the books I've read this month is....
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/118wBG9VziL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Extreme Programming Explained: Embrace Change (2nd Edition) (The XP Series)</b>
                  <br />
by Kent Beck, Cynthia Andres 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321278658%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321278658%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
I really enjoyed reading this book. It paints a picture of what an ideal XP team can
look like and talks about the principals, practices and values of XP. I'd like to
share some excerpts from the book that really stuck out and hand an impact on me.
</p>
        <p>
"If you have six weeks to get a project done, the only thing you can control
is your own behavior. Will you get six weeks' worth of work done or less? you can't
control others' expectations. You can tell them what you know about the project so
their expectations have a chance of matching reality. My terror of deadlines vanished
when I learned this lesson. It's not my job to "manage" someone else's expectations.
It's their job to manage their own expectations. It's my job to do my best and to
communicate clearly."
</p>
        <p>
One of the things I learned about myself is that I hate being late. This isn't a great
trait to have in the world of software development. When I'm handed a deadline I become
so eager to meet it that in the process of racing to the deadline quality is compromised.
I can't control deadlines or others expectations but I can control my own behavior
and if I work consistently as hard as I can without letting go of quality.
</p>
        <p>
"I chose practices for XP because they meet both business and personal needs.
There are other human needs; such as rest, exercise, and socialization; that don't
need to be met in the work environment. Time away from the team gives each individual
more energy and perspective to bring back to the team. Limiting work hours allows
time for these other human needs and enhances each person's contributions while he
is with the team."
</p>
        <p>
It sucks how XP and Agile have become buzzwords in the industry that mean more to
the marketing department then to the software developers. I've said it before and
I'll say it again...
</p>
        <blockquote>
          <p>
"You aren't doing Agile. YOU ARE AGILE!"
</p>
        </blockquote>
        <p>
"Part of the challenge of team software development is balancing the needs of
the individual with the needs of the team. The team's needs may meet your own long-term
individual goals, so are worth some amount of sacrifice. Always sacrificing your own
needs for the team's doesn't work. If I need privacy, I am responsible for find a
ways to get my need met in a way that doesn't hurt the team. The magic of great teams
is that after the team members develop trust they find that they are free to be <em>more</em> themselves
as a result of their work together."
</p>
        <p>
You've got to sacrifice something, regardless of context you're talking about, in
order to succeed. What's important is deciding on what you're willing to sacrifice
in order to get closer to your end goals. I have found that pushing the people outside
of their comfort zone a little bit not only helped me in growing but also the team
as a whole. I also learned that it's important to slow down and reflect. The up and
down rhythm of an XP team is balanced by the different members of a team, and with
trust it's much easier to maintain that balance. 
</p>
        <p>
E.G. Team member A might be a hardcore, heads down, must punch out code as efficiently
as possible. Team member B may be more of a let's take it a little slower and sit
back and think about the problem at hand kind of guy. With trust the two team members
will be able to develop a rhythm that keeps the project going at a sustainable pace
without sacrificing quality.
</p>
        <p>
"I trust two metrics to measure the health of XP teams. The first is the number
of defects found after development. An XP team should have dramatically fewer defects
in its first deployment and make rapid progress from there. Some XP teams that have
been on the path of improvement for several years see only a handful of defects per
year. No defect is acceptable; each is an opportunity for the team to learn and improve."
</p>
        <p>
Test-driven development/design rather then design in your head driven code. The test
is a clear statement of truth. It documents the design that would otherwise be locked
up in your head and is very black of white about whether or not the subject under
test satisfies the test specification or behavior that is expected. If the team is
not disciplined even the best of the best XP teams can forget about the principals
behind the practices, and stop following the practices. One of the most important
things about unit tests is the early feedback. I want to know as soon as possible
when a component in the system is not behaving as expected. By waiting for QA to pick
out bugs, then log a bug, then assign a developer to look at the bug does not deliver
early feedback, I consider this waste! It's a vicious cycle that can be reduced greatly.
</p>
        <p>
"The problem with reviews is that most reviews and raises are based on individual
goals and achievements, but XP focuses on team performance. If a programmer spends
half of his time pairing with others, how can you evaluate his individual performance?
How much incentive does he have to help others if he will be evaluated on individual
performance?"
</p>
        <p>
Out of all the chapters in this book I think chapter 3 is my favorite. It's titled
"Values, Principles, and Practices", and to me it speaks the loudest of
what is XP and why would we want to consider using it as a methodology for building
and delivering software.
</p>
        <p>
I highly recommend this book!
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=1c2e3c8c-5c3e-47bd-aaba-9ef398991acf" />
      </body>
      <title>XP What?</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,1c2e3c8c-5c3e-47bd-aaba-9ef398991acf.aspx</guid>
      <link>http://mokhan.ca/blog/2008/02/01/XP+What.aspx</link>
      <pubDate>Fri, 01 Feb 2008 23:01:41 GMT</pubDate>
      <description>&lt;p&gt;
One of the books I've read this month is....
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/118wBG9VziL.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Extreme Programming Explained: Embrace Change (2nd Edition) (The XP Series)&lt;/b&gt; 
&lt;br /&gt;
by Kent Beck, Cynthia Andres 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321278658%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321278658%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
I really enjoyed reading this book. It paints a picture of what an ideal XP team can
look like and talks about the principals, practices and values of XP. I'd like to
share some excerpts from the book that really stuck out and hand an impact on me.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;If you have six weeks to get a project done, the only thing you can control
is your own behavior. Will you get six weeks' worth of work done or less? you can't
control others' expectations. You can tell them what you know about the project so
their expectations have a chance of matching reality. My terror of deadlines vanished
when I learned this lesson. It's not my job to &amp;quot;manage&amp;quot; someone else's expectations.
It's their job to manage their own expectations. It's my job to do my best and to
communicate clearly.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
One of the things I learned about myself is that I hate being late. This isn't a great
trait to have in the world of software development. When I'm handed a deadline I become
so eager to meet it that in the process of racing to the deadline quality is compromised.
I can't control deadlines or others expectations but I can control my own behavior
and if I work consistently as hard as I can without letting go of quality.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;I chose practices for XP because they meet both business and personal needs.
There are other human needs; such as rest, exercise, and socialization; that don't
need to be met in the work environment. Time away from the team gives each individual
more energy and perspective to bring back to the team. Limiting work hours allows
time for these other human needs and enhances each person's contributions while he
is with the team.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
It sucks how XP and Agile have become buzzwords in the industry that mean more to
the marketing department then to the software developers. I've said it before and
I'll say it again...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;You aren't doing Agile. YOU ARE AGILE!&amp;quot;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;quot;Part of the challenge of team software development is balancing the needs of
the individual with the needs of the team. The team's needs may meet your own long-term
individual goals, so are worth some amount of sacrifice. Always sacrificing your own
needs for the team's doesn't work. If I need privacy, I am responsible for find a
ways to get my need met in a way that doesn't hurt the team. The magic of great teams
is that after the team members develop trust they find that they are free to be &lt;em&gt;more&lt;/em&gt; themselves
as a result of their work together.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
You've got to sacrifice something, regardless of context you're talking about, in
order to succeed. What's important is deciding on what you're willing to sacrifice
in order to get closer to your end goals. I have found that pushing the people outside
of their comfort zone a little bit not only helped me in growing but also the team
as a whole. I also learned that it's important to slow down and reflect. The up and
down rhythm of an XP team is balanced by the different members of a team, and with
trust it's much easier to maintain that balance. 
&lt;/p&gt;
&lt;p&gt;
E.G. Team member A might be a hardcore, heads down, must punch out code as efficiently
as possible. Team member B may be more of a let's take it a little slower and sit
back and think about the problem at hand kind of guy. With trust the two team members
will be able to develop a rhythm that keeps the project going at a sustainable pace
without sacrificing quality.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;I trust two metrics to measure the health of XP teams. The first is the number
of defects found after development. An XP team should have dramatically fewer defects
in its first deployment and make rapid progress from there. Some XP teams that have
been on the path of improvement for several years see only a handful of defects per
year. No defect is acceptable; each is an opportunity for the team to learn and improve.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Test-driven development/design rather then design in your head driven code. The test
is a clear statement of truth. It documents the design that would otherwise be locked
up in your head and is very black of white about whether or not the subject under
test satisfies the test specification or behavior that is expected. If the team is
not disciplined even the best of the best XP teams can forget about the principals
behind the practices, and stop following the practices. One of the most important
things about unit tests is the early feedback. I want to know as soon as possible
when a component in the system is not behaving as expected. By waiting for QA to pick
out bugs, then log a bug, then assign a developer to look at the bug does not deliver
early feedback, I consider this waste! It's a vicious cycle that can be reduced greatly.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;The problem with reviews is that most reviews and raises are based on individual
goals and achievements, but XP focuses on team performance. If a programmer spends
half of his time pairing with others, how can you evaluate his individual performance?
How much incentive does he have to help others if he will be evaluated on individual
performance?&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Out of all the chapters in this book I think chapter 3 is my favorite. It's titled
&amp;quot;Values, Principles, and Practices&amp;quot;, and to me it speaks the loudest of
what is XP and why would we want to consider using it as a methodology for building
and delivering software.
&lt;/p&gt;
&lt;p&gt;
I highly recommend this book!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=1c2e3c8c-5c3e-47bd-aaba-9ef398991acf" /&gt;</description>
      <category>Agile</category>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=48130e27-ae37-49a3-8bb8-8b220ca1839f</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,48130e27-ae37-49a3-8bb8-8b220ca1839f.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just finished reading...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/11jo01WqpQL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Programming .NET Components, 2nd Edition</b>
                  <br />
by Juval Lowy 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596102070%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596102070%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
This was a pretty sweet read, I think this along with CLR via C# work well with one
another. This book goes into a little more depth on threading and issues with concurrency.
As well the chapters on remoting are long and full of tonnes of information. Way more
then this guy could absorb after an initial read. I have so much to learn about remoting.
</p>
        <p>
This book starts right fr gooom the beginning. What is a component?
</p>
        <p>
".. a component is a .NET class. For example, this is a .NET component:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">MyClass</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">string</span> GetMessage()
{ <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(163,21,21)">"Hello"</span>;
} }"</pre>
        <p>
I think one of my favorite chapters in this book was on "Interface-Based Programming"
and talks about the importance of separating interface from implementation. 
</p>
        <p>
"Interface Factoring: When you factor an interface, always think in terms of
reusable elements. In a component-oriented application, the basic unit of reuse is
the interface."
</p>
        <p>
"... proper interface-factoring results in more specialized, loosely coupled,
fine-tuned, and reusable interfaces, and subsequently, those benefits apply to the
system as well. In general, interface factoring results in interfaces with fewer members."
</p>
        <p>
Another benefit, in my opinion, to interfaces is for learning a system. By checking
out the interfaces defined in a subsystem you can get a flavor for what services are
offered by each component. It's much easier to look at the interface contract to see
the operations it performs then having to scan through concrete types. I equate this
to header files in C. If I look at the header file I can see what operations are available
from each library. I don't need to know how it was implemented, just where to find
it.
</p>
        <p>
"Windows Forms base classes make extensive use of ISynchronizeInvoke. The control
class relies on underlying Windows messages and a message-processing loop (the message
pump) to process them. The message loop must have thread affinity, because messages
to a window are delivered only to the thread that created that window."
</p>
        <p>
Juval shares many different helper classes for getting around some of the more trickier
areas of .NET development, like threading, events, remoting and even how to use a <a href="http://msdn2.microsoft.com/en-us/library/ms684266.aspx">mutex</a> to
only allow a single instance of a class to run.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">internal</span>
          <span style="color: rgb(0,0,255)">static</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">Program</span> {
[<span style="color: rgb(43,145,175)">STAThread</span>] <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">void</span> Main()
{ <span style="color: rgb(0,0,255)">if</span> ( IsFirstInstance( ) ) { <span style="color: rgb(43,145,175)">Application</span>.ApplicationExit
+= OnApplicationExit( ); <span style="color: rgb(43,145,175)">Application</span>.Run( <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Form1</span>(
) ); } } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">bool</span> IsFirstInstance()
{ _mutex = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Mutex</span>( <span style="color: rgb(0,0,255)">false</span>, <span style="color: rgb(43,145,175)">Assembly</span>.GetEntryAssembly(
).FullName ); <span style="color: rgb(0,0,255)">bool</span> owned = _mutex.WaitOne( <span style="color: rgb(43,145,175)">TimeSpan</span>.Zero, <span style="color: rgb(0,0,255)">false</span> ); <span style="color: rgb(0,0,255)">return</span> owned;
} <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(43,145,175)">EventHandler</span> OnApplicationExit()
{ <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">delegate</span> {
_mutex.ReleaseMutex( ); _mutex.Close( ); }; } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(43,145,175)">Mutex</span> _mutex;
}</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=48130e27-ae37-49a3-8bb8-8b220ca1839f" />
      </body>
      <title>Programming .NET Components</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,48130e27-ae37-49a3-8bb8-8b220ca1839f.aspx</guid>
      <link>http://mokhan.ca/blog/2007/12/18/Programming+NET+Components.aspx</link>
      <pubDate>Tue, 18 Dec 2007 22:08:36 GMT</pubDate>
      <description>&lt;p&gt;
I just finished reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/11jo01WqpQL.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Programming .NET Components, 2nd Edition&lt;/b&gt; 
&lt;br /&gt;
by Juval Lowy 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596102070%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596102070%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
This was a pretty sweet read, I think this along with CLR via C# work well with one
another. This book goes into a little more depth on threading and issues with concurrency.
As well the chapters on remoting are long and full of tonnes of information. Way more
then this guy could absorb after an initial read. I have so much to learn about remoting.
&lt;/p&gt;
&lt;p&gt;
This book starts right fr gooom the beginning. What is a component?
&lt;/p&gt;
&lt;p&gt;
&amp;quot;.. a component is a .NET class. For example, this is a .NET component:
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;MyClass&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; GetMessage()
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;;
} }&amp;quot;&lt;/pre&gt;
&lt;p&gt;
I think one of my favorite chapters in this book was on &amp;quot;Interface-Based Programming&amp;quot;
and talks about the importance of separating interface from implementation. 
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Interface Factoring: When you factor an interface, always think in terms of
reusable elements. In a component-oriented application, the basic unit of reuse is
the interface.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
&amp;quot;... proper interface-factoring results in more specialized, loosely coupled,
fine-tuned, and reusable interfaces, and subsequently, those benefits apply to the
system as well. In general, interface factoring results in interfaces with fewer members.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Another benefit, in my opinion, to interfaces is for learning a system. By checking
out the interfaces defined in a subsystem you can get a flavor for what services are
offered by each component. It's much easier to look at the interface contract to see
the operations it performs then having to scan through concrete types. I equate this
to header files in C. If I look at the header file I can see what operations are available
from each library. I don't need to know how it was implemented, just where to find
it.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Windows Forms base classes make extensive use of ISynchronizeInvoke. The control
class relies on underlying Windows messages and a message-processing loop (the message
pump) to process them. The message loop must have thread affinity, because messages
to a window are delivered only to the thread that created that window.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Juval shares many different helper classes for getting around some of the more trickier
areas of .NET development, like threading, events, remoting and even how to use a &lt;a href="http://msdn2.microsoft.com/en-us/library/ms684266.aspx"&gt;mutex&lt;/a&gt; to
only allow a single instance of a class to run.
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;internal&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Program&lt;/span&gt; {
[&lt;span style="color: rgb(43,145,175)"&gt;STAThread&lt;/span&gt;] &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Main()
{ &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; ( IsFirstInstance( ) ) { &lt;span style="color: rgb(43,145,175)"&gt;Application&lt;/span&gt;.ApplicationExit
+= OnApplicationExit( ); &lt;span style="color: rgb(43,145,175)"&gt;Application&lt;/span&gt;.Run( &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Form1&lt;/span&gt;(
) ); } } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;bool&lt;/span&gt; IsFirstInstance()
{ _mutex = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Mutex&lt;/span&gt;( &lt;span style="color: rgb(0,0,255)"&gt;false&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;Assembly&lt;/span&gt;.GetEntryAssembly(
).FullName ); &lt;span style="color: rgb(0,0,255)"&gt;bool&lt;/span&gt; owned = _mutex.WaitOne( &lt;span style="color: rgb(43,145,175)"&gt;TimeSpan&lt;/span&gt;.Zero, &lt;span style="color: rgb(0,0,255)"&gt;false&lt;/span&gt; ); &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; owned;
} &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EventHandler&lt;/span&gt; OnApplicationExit()
{ &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;delegate&lt;/span&gt; {
_mutex.ReleaseMutex( ); _mutex.Close( ); }; } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Mutex&lt;/span&gt; _mutex;
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=48130e27-ae37-49a3-8bb8-8b220ca1839f" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=300efeda-1d95-470d-bb21-f66afb2fa543</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,300efeda-1d95-470d-bb21-f66afb2fa543.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'd like to talk to you for a moment about my man The Event Aggregator. (Homeboy's
been tossin' events for years!)
</p>
        <p>
          <a href="http://martinfowler.com/eaaDev/EventAggregator.html">Martin Fowler defines
the Event Aggregator as:</a>
        </p>
        <blockquote>
          <p>
"Channel events from multiple objects into a single object to simplify registration
for clients." - Martin Fowler
</p>
        </blockquote>
        <p>
But he's so much more then that! This pattern comes in handy in state-ful environments,
so.. hello WinForms/WPF. Sorry ASP.NET!
</p>
        <p>
What this guy does is creates a single channel to find out what's going on and to
raise events. Through the event aggregator you can subscribe to known events in the
system as well as raise known events in the system.
</p>
        <p>
Some examples for system wide events are Save, Loading, Shutdown. You can also create
concepts for layer specific event aggregators that target certain layers of a system.
For example UI only.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">ApplicationEvents</span> { <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IEventAggregator</span> aggregator; <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IEvent</span> Save
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">EventRaiser</span>( <span style="color: rgb(163,21,21)">"Save"</span> ); <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IEvent</span> Loading
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">EventRaiser</span>( <span style="color: rgb(163,21,21)">"Loading"</span> ); <span style="color: rgb(0,0,255)">static</span> ApplicationEvents(
) { aggregator = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">EventAggregator</span>(
); aggregator.Register( Save ); aggregator.Register( Loading ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">void</span> Raise( <span style="color: rgb(43,145,175)">IEvent</span> eventToRaise
) { aggregator.RaiseEvent( eventToRaise ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,255)">void</span> SubscribeTo( <span style="color: rgb(43,145,175)">IEvent</span> eventToSubscribeTo, <span style="color: rgb(43,145,175)">EventHandler</span> handler
) { aggregator.AddHandler( eventToSubscribeTo.Name, handler ); } }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
The ApplicationEvents becomes the central point for raising and subscribing to known
application wide events. Type can be coupled to the aggregator but not to each other.
</p>
        <p>
Let's start with the concept of a named event. An event is really nothing more then
a delegate. In .NET there are 2 delegate signatures that are used for all events.
The generic and non generic version of the EventHandler delegate. (<a href="http://mokhan.ca/blog/2007/09/11/Keeping+It+Real+With+Delegates.aspx">Read
More...</a> )
</p>
        <p>
A named event is an event with a name. He might look something like this guy?
</p>
        <p>
    <span style="color: rgb(0,0,255)">internal</span><span style="color: rgb(0,0,255)">class</span><span style="color: rgb(43,145,175)">EventRaiser</span> : <span style="color: rgb(43,145,175)">IEvent</span> {<br />
        <span style="color: rgb(0,0,255)">public</span> EventRaiser( <span style="color: rgb(0,0,255)">string</span> name
) {<br />
            _name = name;<br />
            _handlers = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">List</span>&lt; <span style="color: rgb(43,145,175)">EventHandler</span> &gt;(
);<br />
        }<br /><br />
        <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">string</span> Name
{<br />
            <span style="color: rgb(0,0,255)">get</span> { <span style="color: rgb(0,0,255)">return</span> _name;
}<br />
        }<br /><br />
        <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Add( <span style="color: rgb(43,145,175)">EventHandler</span> handler
) {<br />
            _handlers.Add(
handler );<br />
        }<br /><br />
        <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Raise(
) {<br />
            Raise( <span style="color: rgb(0,0,255)">null</span>, <span style="color: rgb(0,0,255)">null</span> );<br />
        }<br /><br />
        <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Raise( <span style="color: rgb(0,0,255)">object</span> sender, <span style="color: rgb(43,145,175)">EventArgs</span> data
) {<br />
            <span style="color: rgb(0,0,255)">foreach</span> ( <span style="color: rgb(43,145,175)">EventHandler</span> handler <span style="color: rgb(0,0,255)">in</span> _handlers
) {<br />
                <span style="color: rgb(0,0,255)">if</span> (
handler != <span style="color: rgb(0,0,255)">null</span> ) {<br />
                   
handler( sender, data );<br />
               
}<br />
            }            
<br />
        }<br /><br />
        <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(0,0,255)">string</span> _name;<br />
        <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IList</span>&lt; <span style="color: rgb(43,145,175)">EventHandler</span> &gt;
_handlers;<br />
    }
</p>
        <p>
Underneath the hood it's the aggregator that's maintaining references to all the types
that have subscribed to events.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">EventAggregator</span> : <span style="color: rgb(43,145,175)">IEventAggregator</span> { <span style="color: rgb(0,0,255)">public</span> EventAggregator(
) { _events = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Dictionary</span>&lt; <span style="color: rgb(0,0,255)">string</span>, <span style="color: rgb(43,145,175)">IEvent</span> &gt;(
); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Register( <span style="color: rgb(0,0,255)">string</span> eventName
) { Register( <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">EventRaiser</span>(
eventName ) ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Register( <span style="color: rgb(43,145,175)">IEvent</span> eventToAdd
) { EnsureEventHasntBeenRegistered( eventToAdd ); _events.Add( eventToAdd.Name, eventToAdd
); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> AddHandler( <span style="color: rgb(0,0,255)">string</span> eventName, <span style="color: rgb(43,145,175)">EventHandler</span> handler
) { RetrieveEvent( eventName ).Add( handler ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> RaiseEvent( <span style="color: rgb(0,0,255)">string</span> withEventName
) { RaiseEvent&lt; <span style="color: rgb(43,145,175)">EventArgs</span> &gt;( withEventName, <span style="color: rgb(0,0,255)">null</span>, <span style="color: rgb(43,145,175)">EventArgs</span>.Empty
); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> RaiseEvent( <span style="color: rgb(43,145,175)">IEvent</span> eventToRaise
) { RaiseEvent&lt; <span style="color: rgb(43,145,175)">EventArgs</span> &gt;( eventToRaise.Name, <span style="color: rgb(0,0,255)">null</span>, <span style="color: rgb(43,145,175)">EventArgs</span>.Empty
); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> RaiseEvent&lt;
T &gt;( <span style="color: rgb(0,0,255)">string</span> withEventName, <span style="color: rgb(0,0,255)">object</span> sender,
T data ) <span style="color: rgb(0,0,255)">where</span> T : <span style="color: rgb(43,145,175)">EventArgs</span> {
RetrieveEvent( withEventName ).Raise( sender, data ); } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(43,145,175)">IEvent</span> RetrieveEvent( <span style="color: rgb(0,0,255)">string</span> eventName
) { <span style="color: rgb(0,0,255)">if</span> ( _events.ContainsKey( eventName )
) { <span style="color: rgb(0,0,255)">return</span> _events[ eventName ]; } <span style="color: rgb(0,0,255)">throw</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">ArgumentNullException</span>(
eventName, <span style="color: rgb(163,21,21)">"The Event Has Not Been Registered."</span> );
} <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">void</span> EnsureEventHasntBeenRegistered( <span style="color: rgb(43,145,175)">IEvent</span> eventToAdd
) { <span style="color: rgb(0,0,255)">if</span> ( _events.ContainsKey( eventToAdd.Name
) ) { <span style="color: rgb(0,0,255)">throw</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">ArgumentException</span>( <span style="color: rgb(163,21,21)">"Event
name has already been registered"</span>, eventToAdd.Name ); } } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDictionary</span>&lt; <span style="color: rgb(0,0,255)">string</span>, <span style="color: rgb(43,145,175)">IEvent</span> &gt;
_events; }</pre>
        <pre class="code">
        </pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
The concept is similar to <a href="http://books.google.com/books?id=dSiuGk0RZ4gC&amp;pg=PA252&amp;lpg=PA252&amp;dq=programming+net+components+eventshelper&amp;source=web&amp;ots=wxecinntRh&amp;sig=wGtAYldHgy0WI3xltfPt1CcqNfI#PPA251,M1">Juval
Lowy's EventHelper class</a> defined in...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/11jo01WqpQL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Programming .NET Components, 2nd Edition</b>
                  <br />
by Juval Lowy<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596102070%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596102070%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=300efeda-1d95-470d-bb21-f66afb2fa543" />
      </body>
      <title>The Event Aggregator</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,300efeda-1d95-470d-bb21-f66afb2fa543.aspx</guid>
      <link>http://mokhan.ca/blog/2007/12/18/The+Event+Aggregator.aspx</link>
      <pubDate>Tue, 18 Dec 2007 21:26:11 GMT</pubDate>
      <description>&lt;p&gt;
I'd like to talk to you for a moment about my man The Event Aggregator. (Homeboy's
been tossin' events for years!)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://martinfowler.com/eaaDev/EventAggregator.html"&gt;Martin Fowler defines
the Event Aggregator as:&lt;/a&gt;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"Channel events from multiple objects into a single object to simplify registration
for clients." - Martin Fowler
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
But he's so much more then that! This pattern comes in handy in state-ful environments,
so.. hello WinForms/WPF. Sorry ASP.NET!
&lt;/p&gt;
&lt;p&gt;
What this guy does is creates a single channel to find out what's going on and to
raise events. Through the event aggregator you can subscribe to known events in the
system as well as raise known events in the system.
&lt;/p&gt;
&lt;p&gt;
Some examples for system wide events are Save, Loading, Shutdown. You can also create
concepts for layer specific event aggregators that target certain layers of a system.
For example UI only.
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ApplicationEvents&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IEventAggregator&lt;/span&gt; aggregator; &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; Save
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EventRaiser&lt;/span&gt;( &lt;span style="color: rgb(163,21,21)"&gt;"Save"&lt;/span&gt; ); &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; Loading
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EventRaiser&lt;/span&gt;( &lt;span style="color: rgb(163,21,21)"&gt;"Loading"&lt;/span&gt; ); &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; ApplicationEvents(
) { aggregator = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EventAggregator&lt;/span&gt;(
); aggregator.Register( Save ); aggregator.Register( Loading ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Raise( &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; eventToRaise
) { aggregator.RaiseEvent( eventToRaise ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; SubscribeTo( &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; eventToSubscribeTo, &lt;span style="color: rgb(43,145,175)"&gt;EventHandler&lt;/span&gt; handler
) { aggregator.AddHandler( eventToSubscribeTo.Name, handler ); } }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
The ApplicationEvents becomes the central point for raising and subscribing to known
application wide events. Type can be coupled to the aggregator but not to each other.
&lt;/p&gt;
&lt;p&gt;
Let's start with the concept of a named event. An event is really nothing more then
a delegate. In .NET there are 2 delegate signatures that are used for all events.
The generic and non generic version of the EventHandler delegate. (&lt;a href="http://mokhan.ca/blog/2007/09/11/Keeping+It+Real+With+Delegates.aspx"&gt;Read
More...&lt;/a&gt; )
&lt;/p&gt;
&lt;p&gt;
A named event is an event with a name. He might look something like this guy?
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;internal&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EventRaiser&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; EventRaiser( &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; name
) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _name = name;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _handlers = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;List&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;EventHandler&lt;/span&gt; &amp;gt;(
);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; Name
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; _name;
}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Add( &lt;span style="color: rgb(43,145,175)"&gt;EventHandler&lt;/span&gt; handler
) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _handlers.Add(
handler );&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Raise(
) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Raise( &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt; );&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Raise( &lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt; data
) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;foreach&lt;/span&gt; ( &lt;span style="color: rgb(43,145,175)"&gt;EventHandler&lt;/span&gt; handler &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; _handlers
) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; (
handler != &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt; ) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
handler( sender, data );&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; _name;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IList&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;EventHandler&lt;/span&gt; &amp;gt;
_handlers;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
Underneath the hood it's the aggregator that's maintaining references to all the types
that have subscribed to events.
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EventAggregator&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;IEventAggregator&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; EventAggregator(
) { _events = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Dictionary&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; &amp;gt;(
); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Register( &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; eventName
) { Register( &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EventRaiser&lt;/span&gt;(
eventName ) ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Register( &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; eventToAdd
) { EnsureEventHasntBeenRegistered( eventToAdd ); _events.Add( eventToAdd.Name, eventToAdd
); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; AddHandler( &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; eventName, &lt;span style="color: rgb(43,145,175)"&gt;EventHandler&lt;/span&gt; handler
) { RetrieveEvent( eventName ).Add( handler ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; RaiseEvent( &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; withEventName
) { RaiseEvent&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt; &amp;gt;( withEventName, &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt;.Empty
); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; RaiseEvent( &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; eventToRaise
) { RaiseEvent&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt; &amp;gt;( eventToRaise.Name, &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt;.Empty
); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; RaiseEvent&amp;lt;
T &amp;gt;( &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; withEventName, &lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt; sender,
T data ) &lt;span style="color: rgb(0,0,255)"&gt;where&lt;/span&gt; T : &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt; {
RetrieveEvent( withEventName ).Raise( sender, data ); } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; RetrieveEvent( &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; eventName
) { &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; ( _events.ContainsKey( eventName )
) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; _events[ eventName ]; } &lt;span style="color: rgb(0,0,255)"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ArgumentNullException&lt;/span&gt;(
eventName, &lt;span style="color: rgb(163,21,21)"&gt;"The Event Has Not Been Registered."&lt;/span&gt; );
} &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; EnsureEventHasntBeenRegistered( &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; eventToAdd
) { &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; ( _events.ContainsKey( eventToAdd.Name
) ) { &lt;span style="color: rgb(0,0,255)"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ArgumentException&lt;/span&gt;( &lt;span style="color: rgb(163,21,21)"&gt;"Event
name has already been registered"&lt;/span&gt;, eventToAdd.Name ); } } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDictionary&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;IEvent&lt;/span&gt; &amp;gt;
_events; }&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
The concept is similar to &lt;a href="http://books.google.com/books?id=dSiuGk0RZ4gC&amp;amp;pg=PA252&amp;amp;lpg=PA252&amp;amp;dq=programming+net+components+eventshelper&amp;amp;source=web&amp;amp;ots=wxecinntRh&amp;amp;sig=wGtAYldHgy0WI3xltfPt1CcqNfI#PPA251,M1"&gt;Juval
Lowy's EventHelper class&lt;/a&gt; defined in...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/11jo01WqpQL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Programming .NET Components, 2nd Edition&lt;/b&gt;
&lt;br&gt;
by Juval Lowy&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596102070%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596102070%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=300efeda-1d95-470d-bb21-f66afb2fa543" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
      <category>Design Patterns</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=a9eaf4a2-5b69-4da1-bba1-ea91cbc70bfc</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,a9eaf4a2-5b69-4da1-bba1-ea91cbc70bfc.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This week while I'm at home on holidays, I've been reading...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/01SK85BS8EL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Patterns of Enterprise Application Architecture (The Addison-Wesley Signature Series)</b>
                  <br />
by Martin Fowler 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321127420%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321127420%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
This book is amazing, I could probably read it over and over again. The patterns that
it presents makes a lot of sense, the actual implementations and examples could probably
re-vamped but I'm finding that it's a great starter to trying to understand the concepts.
</p>
        <p>
So today I'm trying to grok this concept of the "IDENTITY MAP". The book
defines it as:
</p>
        <p>
"Ensures that each object gets loaded only once by keeping every loaded object
in a map. Looks up objects using the map when referring to them."
</p>
        <p>
I put together a quick implementation that I'm using for an assignment I'm writing
for school. I'm creating repositories that have 2 dependencies. First dependency is
a Data Mapper (not to be confused with a Mapper) and the second is an Identity Map.
</p>
        <p>
As objects are requested from the repository, the repository is checking the identity
map to see if an instance has been loaded, if it has it's immediately returned to
the caller. If the object is not in the map the repository leverages the data mapper
to load the object, then adds it to the map and returns it to the caller.
</p>
        <p>
The Data Mapper is defined as:
</p>
        <blockquote>
          <p>
"A layer of Mappers that moves data between objects and a database while keeping
them independent of each other and the mapper itself." - PoEAA
</p>
        </blockquote>
        <p>
I created a Layer Supertype to register objects in the map. The Domain Layer Super
type demands that domain objects had an ID. The ID is what's getting used to load
and register objects into the map. 
</p>
        <p>
The Layer Supertype is defined as:
</p>
        <blockquote>
          <p>
"A type that acts as a the supertype for all types in it's layer." - PoEAA
</p>
        </blockquote>
        <p>
The Domain Layer Super Type.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">interface</span>
          <span style="color: rgb(43,145,175)">IDomainObject</span> { <span style="color: rgb(0,0,255)">long</span> ID();
}</pre>
        <p>
My actual implementation of the identity map looks like this...
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">IdentityMap</span>&lt;
T &gt; : <span style="color: rgb(43,145,175)">IIdentityMap</span>&lt; T &gt; <span style="color: rgb(0,0,255)">where</span> T
: <span style="color: rgb(43,145,175)">IDomainObject</span> { <span style="color: rgb(0,0,255)">public</span> IdentityMap()
{ _items = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">List</span>&lt;
T &gt;( ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Add(
T domainObject ) { EnsureObjectHasNotAlreadyBeenAdded( domainObject ); _items.Add(
domainObject ); } <span style="color: rgb(0,0,255)">public</span> T FindObjectWithIdOf( <span style="color: rgb(0,0,255)">long</span> idOfObjectToFind
) { <span style="color: rgb(0,0,255)">foreach</span> ( T item <span style="color: rgb(0,0,255)">in</span> _items
) { <span style="color: rgb(0,0,255)">if</span> ( item.ID( ).Equals( idOfObjectToFind
) ) { <span style="color: rgb(0,0,255)">return</span> item; } } <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">default</span>(
T ); } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">void</span> EnsureObjectHasNotAlreadyBeenAdded(
T domainObject ) { <span style="color: rgb(0,0,255)">if</span> ( ContainsObjectWithIdOf(
domainObject.ID( ) ) ) { <span style="color: rgb(0,0,255)">throw</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">ObjectAlreadyAddedToIdentityMapException</span>(
domainObject ); } } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IList</span>&lt;
T &gt; _items; }</pre>
        <p>
One of the benefits I like about the Identity Map is that it acts as an in memory
cache for objects loaded from the database. This reduces the number of trips to and
from the persistence store.
</p>
        <p>
          <a href="http://mokhan.ca/blog/content/binary/IdentityMapExample.txt">Source Code</a>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=a9eaf4a2-5b69-4da1-bba1-ea91cbc70bfc" />
      </body>
      <title>The Identity Map</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,a9eaf4a2-5b69-4da1-bba1-ea91cbc70bfc.aspx</guid>
      <link>http://mokhan.ca/blog/2007/12/18/The+Identity+Map.aspx</link>
      <pubDate>Tue, 18 Dec 2007 19:21:21 GMT</pubDate>
      <description>&lt;p&gt;
This week while I'm at home on holidays, I've been reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/01SK85BS8EL.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Patterns of Enterprise Application Architecture (The Addison-Wesley Signature Series)&lt;/b&gt; 
&lt;br /&gt;
by Martin Fowler 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321127420%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321127420%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
This book is amazing, I could probably read it over and over again. The patterns that
it presents makes a lot of sense, the actual implementations and examples could probably
re-vamped but I'm finding that it's a great starter to trying to understand the concepts.
&lt;/p&gt;
&lt;p&gt;
So today I'm trying to grok this concept of the &amp;quot;IDENTITY MAP&amp;quot;. The book
defines it as:
&lt;/p&gt;
&lt;p&gt;
&amp;quot;Ensures that each object gets loaded only once by keeping every loaded object
in a map. Looks up objects using the map when referring to them.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
I put together a quick implementation that I'm using for an assignment I'm writing
for school. I'm creating repositories that have 2 dependencies. First dependency is
a Data Mapper (not to be confused with a Mapper) and the second is an Identity Map.
&lt;/p&gt;
&lt;p&gt;
As objects are requested from the repository, the repository is checking the identity
map to see if an instance has been loaded, if it has it's immediately returned to
the caller. If the object is not in the map the repository leverages the data mapper
to load the object, then adds it to the map and returns it to the caller.
&lt;/p&gt;
&lt;p&gt;
The Data Mapper is defined as:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;A layer of Mappers that moves data between objects and a database while keeping
them independent of each other and the mapper itself.&amp;quot; - PoEAA
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I created a Layer Supertype to register objects in the map. The Domain Layer Super
type demands that domain objects had an ID. The ID is what's getting used to load
and register objects into the map. 
&lt;/p&gt;
&lt;p&gt;
The Layer Supertype is defined as:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;A type that acts as a the supertype for all types in it's layer.&amp;quot; - PoEAA
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
The Domain Layer Super Type.
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDomainObject&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;long&lt;/span&gt; ID();
}&lt;/pre&gt;
&lt;p&gt;
My actual implementation of the identity map looks like this...
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IdentityMap&lt;/span&gt;&amp;lt;
T &amp;gt; : &lt;span style="color: rgb(43,145,175)"&gt;IIdentityMap&lt;/span&gt;&amp;lt; T &amp;gt; &lt;span style="color: rgb(0,0,255)"&gt;where&lt;/span&gt; T
: &lt;span style="color: rgb(43,145,175)"&gt;IDomainObject&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; IdentityMap()
{ _items = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;List&lt;/span&gt;&amp;lt;
T &amp;gt;( ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Add(
T domainObject ) { EnsureObjectHasNotAlreadyBeenAdded( domainObject ); _items.Add(
domainObject ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; T FindObjectWithIdOf( &lt;span style="color: rgb(0,0,255)"&gt;long&lt;/span&gt; idOfObjectToFind
) { &lt;span style="color: rgb(0,0,255)"&gt;foreach&lt;/span&gt; ( T item &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; _items
) { &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; ( item.ID( ).Equals( idOfObjectToFind
) ) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; item; } } &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;default&lt;/span&gt;(
T ); } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; EnsureObjectHasNotAlreadyBeenAdded(
T domainObject ) { &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; ( ContainsObjectWithIdOf(
domainObject.ID( ) ) ) { &lt;span style="color: rgb(0,0,255)"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ObjectAlreadyAddedToIdentityMapException&lt;/span&gt;(
domainObject ); } } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IList&lt;/span&gt;&amp;lt;
T &amp;gt; _items; }&lt;/pre&gt;
&lt;p&gt;
One of the benefits I like about the Identity Map is that it acts as an in memory
cache for objects loaded from the database. This reduces the number of trips to and
from the persistence store.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://mokhan.ca/blog/content/binary/IdentityMapExample.txt"&gt;Source Code&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=a9eaf4a2-5b69-4da1-bba1-ea91cbc70bfc" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
      <category>Design Patterns</category>
      <category>Generics</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=fcfdbaa1-1396-4ce6-aef2-814bd2bb4857</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,fcfdbaa1-1396-4ce6-aef2-814bd2bb4857.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
On Thursday I finished reading...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/11BG9CFR98L.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Working Effectively with Legacy Code (Robert C. Martin Series)</b>
                  <br />
by Michael Feathers 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131177052%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0131177052%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
This was a pretty sweet read, but I think I would have gained more value from it if
I were currently working on a legacy code base. (Please <strong>Don't read that as</strong>...
"I want to work on a legacy code base.")
</p>
        <p>
This book is loaded with a catalog of refactorings to improve the design of existing
code and get it under a test harness. Below is a list of some of the quotes from the
book that I stuck out for me...
</p>
        <blockquote>
          <p>
"The Legacy Code Change Algorithm
</p>
          <ol>
            <li>
Identify change points. 
</li>
            <li>
Find test points. 
</li>
            <li>
Break dependencies 
</li>
            <li>
Write tests. 
</li>
            <li>
Make changes and refactor. 
</li>
          </ol>
          <p>
Over time, tested areas of the code base surface like islands rising out of the ocean."
</p>
        </blockquote>
        <blockquote>
          <p>
"Mock objects are fakes that perform assertions internally."
</p>
        </blockquote>
        <blockquote>
          <p>
"...it is better to depend on interfaces or abstract classes than it is to depend
on concrete classes. When you depend on less volatile things, you minimize the chance
that particular changes will trigger massive recompilation."
</p>
        </blockquote>
        <blockquote>
          <p>
"The heuristics for identifying responsibilities can really help you dig in and
find new abstractions in old classes, but they are just tricks. The way to really
get better at identification is to read more. Read books about design patterns. More
important, read other people's code. Look at open-source projects, and just take some
time to browse and see how other people do things. Pay attention to how classes are
named and the correspondence between class names and the names of methods. Over time,
you'll get better at identifying hidden responsibilities, and you'll just start to
see them when you browse unfamiliar code."
</p>
        </blockquote>
        <blockquote>
          <p>
"... when I first thought about becoming a programmer, I was really captivated
by stories about super-smart programmers, those guys and gals who could keep the state
of an entire system in their heads, write correct code on the fly, and know immediately
whether some change was right or wrong...
</p>
          <p>
Holding on to a lot of state mentally can be useful, but it doesn't really make us
better at decision-making. At this point in my career, I think I'm a much better programmer
than I used to be, even though I know less about the details of each language I work
in."
</p>
        </blockquote>
        <blockquote>
          <p>
"When interfaces were first introduced in languages, some people started naming
interfaces by placing and "I" before the name of the class they were gleaned
from...
</p>
          <p>
The advantage to this sort of naming is that you don't really have to think about
the name when you the extraction. The disadvantage is that you end up with a lot of
code that has to know whether it is dealing with an interface. Ideally, it shouldn't
care one way or another."
</p>
        </blockquote>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=fcfdbaa1-1396-4ce6-aef2-814bd2bb4857" />
      </body>
      <title>Strap It Into The Test Harness</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,fcfdbaa1-1396-4ce6-aef2-814bd2bb4857.aspx</guid>
      <link>http://mokhan.ca/blog/2007/11/24/Strap+It+Into+The+Test+Harness.aspx</link>
      <pubDate>Sat, 24 Nov 2007 18:33:05 GMT</pubDate>
      <description>&lt;p&gt;
On Thursday I finished reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/11BG9CFR98L.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Working Effectively with Legacy Code (Robert C. Martin Series)&lt;/b&gt; 
&lt;br /&gt;
by Michael Feathers 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131177052%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0131177052%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
This was a pretty sweet read, but I think I would have gained more value from it if
I were currently working on a legacy code base. (Please &lt;strong&gt;Don't read that as&lt;/strong&gt;...
&amp;quot;I want to work on a legacy code base.&amp;quot;)
&lt;/p&gt;
&lt;p&gt;
This book is loaded with a catalog of refactorings to improve the design of existing
code and get it under a test harness. Below is a list of some of the quotes from the
book that I stuck out for me...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;The Legacy Code Change Algorithm
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Identify change points. 
&lt;/li&gt;
&lt;li&gt;
Find test points. 
&lt;/li&gt;
&lt;li&gt;
Break dependencies 
&lt;/li&gt;
&lt;li&gt;
Write tests. 
&lt;/li&gt;
&lt;li&gt;
Make changes and refactor. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Over time, tested areas of the code base surface like islands rising out of the ocean.&amp;quot;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;Mock objects are fakes that perform assertions internally.&amp;quot;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;...it is better to depend on interfaces or abstract classes than it is to depend
on concrete classes. When you depend on less volatile things, you minimize the chance
that particular changes will trigger massive recompilation.&amp;quot;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;The heuristics for identifying responsibilities can really help you dig in and
find new abstractions in old classes, but they are just tricks. The way to really
get better at identification is to read more. Read books about design patterns. More
important, read other people's code. Look at open-source projects, and just take some
time to browse and see how other people do things. Pay attention to how classes are
named and the correspondence between class names and the names of methods. Over time,
you'll get better at identifying hidden responsibilities, and you'll just start to
see them when you browse unfamiliar code.&amp;quot;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;... when I first thought about becoming a programmer, I was really captivated
by stories about super-smart programmers, those guys and gals who could keep the state
of an entire system in their heads, write correct code on the fly, and know immediately
whether some change was right or wrong...
&lt;/p&gt;
&lt;p&gt;
Holding on to a lot of state mentally can be useful, but it doesn't really make us
better at decision-making. At this point in my career, I think I'm a much better programmer
than I used to be, even though I know less about the details of each language I work
in.&amp;quot;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&amp;quot;When interfaces were first introduced in languages, some people started naming
interfaces by placing and &amp;quot;I&amp;quot; before the name of the class they were gleaned
from...
&lt;/p&gt;
&lt;p&gt;
The advantage to this sort of naming is that you don't really have to think about
the name when you the extraction. The disadvantage is that you end up with a lot of
code that has to know whether it is dealing with an interface. Ideally, it shouldn't
care one way or another.&amp;quot;
&lt;/p&gt;
&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=fcfdbaa1-1396-4ce6-aef2-814bd2bb4857" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=502ccdb1-f327-49d5-9195-8a5713c92ea7</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,502ccdb1-f327-49d5-9195-8a5713c92ea7.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When I moved my DasBlog on to GoDaddy I found that my captcha controls (comment view
and email view) were no longer showing. In the event log I was reading the following
exception...
</p>
        <p>
I'm paying for the cheapest possible plan i could find on GoDaddy which was the Economy
Plan, I'm not sure if this following step is necessary if you're paying for a <a href="http://www.jameskovacs.com/blog/ImBack.aspx">virtual
dedicated host</a>.
</p>
        <p>
"System.TypeInitializationException: The type initializer for 'Gdip' threw an
exception. ---&gt; System.DllNotFoundException: Unable to load DLL 'gdiplus.dll':"
</p>
        <p>
DasBlog doesn't ship with "Gdiplus.dll" so you'll have to <a href="http://www.driverskit.net/dll/get/901.html">download
it</a> and drop it into the bin directory.
</p>
        <p>
          <a href="http://mokhan.ca/blog/content/binary/WindowsLiveWriter/b099c022e688_7B91/gdiplus.png">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="480" alt="gdiplus" src="http://mokhan.ca/blog/content/binary/WindowsLiveWriter/b099c022e688_7B91/gdiplus_thumb.png" width="594" border="0" />
          </a>
        </p>
        <p>
Thanks for your help, <a href="http://graysmatter.codivation.com/">Mr. Justice</a>! 
</p>
        <p>
While I'm at it, I should drop a plug for...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/11DG5xWJtHL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>The Money Book for the Young, Fabulous &amp; Broke</b>
                  <br />
by Suze Orman 
<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=1594482241%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/1594482241%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
It's catered to an American audience, but I really enjoyed it. It was a fresh and
funky take on finances.<img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=502ccdb1-f327-49d5-9195-8a5713c92ea7" /></body>
      <title>Hosting DasBlog on GoDaddy for the young, fabulous and broke</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,502ccdb1-f327-49d5-9195-8a5713c92ea7.aspx</guid>
      <link>http://mokhan.ca/blog/2007/11/22/Hosting+DasBlog+On+GoDaddy+For+The+Young+Fabulous+And+Broke.aspx</link>
      <pubDate>Thu, 22 Nov 2007 15:52:07 GMT</pubDate>
      <description>&lt;p&gt;
When I moved my DasBlog on to GoDaddy I found that my captcha controls (comment view
and email view) were no longer showing. In the event log I was reading the following
exception...
&lt;/p&gt;
&lt;p&gt;
I'm paying for the cheapest possible plan i could find on GoDaddy which was the Economy
Plan, I'm not sure if this following step is necessary if you're paying for a &lt;a href="http://www.jameskovacs.com/blog/ImBack.aspx"&gt;virtual
dedicated host&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&amp;quot;System.TypeInitializationException: The type initializer for 'Gdip' threw an
exception. ---&amp;gt; System.DllNotFoundException: Unable to load DLL 'gdiplus.dll':&amp;quot;
&lt;/p&gt;
&lt;p&gt;
DasBlog doesn't ship with &amp;quot;Gdiplus.dll&amp;quot; so you'll have to &lt;a href="http://www.driverskit.net/dll/get/901.html"&gt;download
it&lt;/a&gt; and drop it into the bin directory.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://mokhan.ca/blog/content/binary/WindowsLiveWriter/b099c022e688_7B91/gdiplus.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="480" alt="gdiplus" src="http://mokhan.ca/blog/content/binary/WindowsLiveWriter/b099c022e688_7B91/gdiplus_thumb.png" width="594" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Thanks for your help, &lt;a href="http://graysmatter.codivation.com/"&gt;Mr. Justice&lt;/a&gt;! 
&lt;/p&gt;
&lt;p&gt;
While I'm at it, I should drop a plug for...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/11DG5xWJtHL.jpg" border="1" /&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;The Money Book for the Young, Fabulous &amp;amp; Broke&lt;/b&gt; 
&lt;br /&gt;
by Suze Orman 
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=1594482241%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/1594482241%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
It's catered to an American audience, but I really enjoyed it. It was a fresh and
funky take on finances.&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=502ccdb1-f327-49d5-9195-8a5713c92ea7" /&gt;</description>
      <category>Books</category>
      <category>Journal</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=b86a1dff-7abe-442f-8704-4c3d8f696c45</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,b86a1dff-7abe-442f-8704-4c3d8f696c45.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm currently reading...
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ecx.images-amazon.com/images/I/1171%2BsUjCPL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Domain-Driven Design: Tackling Complexity in the Heart of Software</b>
                  <br />
by Eric Evans<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321125215%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321125215%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
It's really as good as they say it is! And it's got me thinking... I really enjoy
reading a book that makes me think, I sometimes prefer reading tech books that only
give you concepts to think about. It's up to you to understand those concepts then
find a way to implement them when you see their use is necessary. There's a lot of
great concepts that came from this book, and after seeing them out in the wild in
episodes of DNRTV and source code buried in svn repositories it's all starting to
make sense...
</p>
        <ul>
          <li>
            <strong>Entities:</strong> An object defined primarily by its identity is called an
Entity. 
</li>
          <li>
            <strong>Value Objects:</strong> An object that describes some characteristic or attribute
but carries no concept of identity. 
</li>
          <li>
            <strong>Aggregates:</strong> A cluster of associated objects that are treated as a
unit for the purpose of data changes. 
</li>
          <li>
            <strong>Repositories:</strong> A mechanism for encapsulating storage, retrieval, and
search behavior which emulates a collection of objects. 
</li>
          <li>
            <strong>Services:</strong> An operation offered as an interface that stands alone
in the model, with no encapsulated state. 
</li>
          <li>
            <strong>Specifications:</strong> A predicate that determines if an object does or
does not satisfy some criteria.</li>
        </ul>
        <p>
          <font size="1">*Note: the definitions above are right out of the glossary.</font>
        </p>
        <p>
The toughest part to grasp and seems to be the underlying theme of this book is "The
Ubiquitous Language". The tough part is not grasping the "concept" but rather the
implementation. The concept makes a lot of sense, but how you can practically apply
it is a separate story. One that I think takes experience through trial and error.
Time will tell...
</p>
        <p>
Go buy this book, I know I will... until then thank you <a href="http://blog.streamlinelogic.ca/">Mr.
Adam!</a> (just in case I can't I put it on my wish list for Santa, he always
pulls through!)
</p>
        <p>
After reading through some examples on specifications and reading through JP's example,
this sparked some ideas in my mind. So I hacked together some code and came up with
this. Let's say I've got a bank of questions, and that each question is part of a
category, and I want to be able to search through the bank of questions...
</p>
        <pre class="code">[Test]
<span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Should_Return_3_Questions_That_Are_Not_Math(
) { <span style="color: rgb(43,145,175)">IEnumerable</span>&lt; <span style="color: rgb(43,145,175)">IQuestion</span> &gt;
matches = CreateSut( ).FindAllWhere( <span style="color: rgb(43,145,175)">Question</span>.IsIn( <span style="color: rgb(43,145,175)">Any</span>.Category
).But( <span style="color: rgb(43,145,175)">Not</span>.In( <span style="color: rgb(43,145,175)">Category</span>.Math
) ) ); <span style="color: rgb(43,145,175)">Assert</span>.AreEqual( 3, GetCountFor(
matches ) ); }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <a href="http://11011.net/software/vspaste">
        </a>
        <blockquote>
          <p>
Notice the use of "But", I wonder if this will catch on... 
</p>
        </blockquote>
        <p>
Basically I started looking into creating specification for boolean operations, with
a slightly different take from what the book offered and inspired by <a href="http://www.jpboodhoo.com/blog/EnglandGenericsPresentationSourceCode.aspx">JP</a> and <a href="http://www.ayende.com/Blog/archive/2007/06/05/RepositoryltTgt-Syntactic-Sugar-and-DDD.aspx">Ayende</a>.
I'm not sure it's the most elegant interface, but I really wanted to be able to make
the client code as readable as possible.
</p>
        <p>
What I ended up with was types like "Is", "Not", "And" &amp; "Or". I'm not sure I'm
completely happy with the end product, but I see potential for extending this further,
and the best part is how readable the code seems to be. I think that excites me more
then anything else... I think I'm just starting to understand this concept of the
"fluent" interface. Not truly implementing it well, seems to be difficult, but fun!
</p>
        <p>
Here's what my Question type turned in too...
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">Question</span> : <span style="color: rgb(43,145,175)">IQuestion</span> { <span style="color: rgb(0,0,255)">public</span> Question( <span style="color: rgb(43,145,175)">ICategory</span> category
) { _category = category; } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(43,145,175)">ICategory</span> Category
{ <span style="color: rgb(0,0,255)">get</span> { <span style="color: rgb(0,0,255)">return</span> _category;
} } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(43,145,175)">ISpecification</span>&lt; <span style="color: rgb(43,145,175)">IQuestion</span> &gt;
IsIn( <span style="color: rgb(43,145,175)">ICategory</span> category ) { <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(43,145,175)">Is</span>.In(
category ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(43,145,175)">ISpecification</span>&lt; <span style="color: rgb(43,145,175)">IQuestion</span> &gt;
IsNotIn( <span style="color: rgb(43,145,175)">ICategory</span> category ) { <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(43,145,175)">Not</span>.In(
category ); } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">ICategory</span> _category;
} </pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>The Is type looks like... 
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">Is</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(43,145,175)">ISpecification</span>&lt; <span style="color: rgb(43,145,175)">IQuestion</span> &gt;
In( <span style="color: rgb(43,145,175)">ICategory</span> category ) { <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Specification</span>&lt; <span style="color: rgb(43,145,175)">IQuestion</span> &gt;( <span style="color: rgb(0,0,255)">delegate</span>( <span style="color: rgb(43,145,175)">IQuestion</span> question
) { <span style="color: rgb(0,0,255)">return</span> category.Equals( question.Category
); } ); } } </pre>
        <p>
And the "Not" type looks like...
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">Not</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(43,145,175)">ISpecification</span>&lt; <span style="color: rgb(43,145,175)">IQuestion</span> &gt;
In( <span style="color: rgb(43,145,175)">ICategory</span> category ) { <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Specification</span>&lt; <span style="color: rgb(43,145,175)">IQuestion</span> &gt;( <span style="color: rgb(0,0,255)">delegate</span>( <span style="color: rgb(43,145,175)">IQuestion</span> question
) { <span style="color: rgb(0,0,255)">return</span> !category.Equals( question.Category
); } ); } } </pre>
        <p>
To me it still seems that the "Not" and "Is" types shouldn't be responsible for returning
the specification, and that responsibility should belong to the Question, but I'm
just not sure... and it's getting rather late so I should head to bed.
</p>
        <p>
Source is attached!
</p>
        <hints id="hah_hints">
        </hints>
        <a href="http://mokhan.ca/blog/content/binary/PlayingWithSpecifications.zip">PlayingWithSpecifications.zip
(2.17 MB)</a>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b86a1dff-7abe-442f-8704-4c3d8f696c45" />
      </body>
      <title>Complexity Simplified</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,b86a1dff-7abe-442f-8704-4c3d8f696c45.aspx</guid>
      <link>http://mokhan.ca/blog/2007/10/27/Complexity+Simplified.aspx</link>
      <pubDate>Sat, 27 Oct 2007 07:47:17 GMT</pubDate>
      <description>&lt;p&gt;
I'm currently reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ecx.images-amazon.com/images/I/1171%2BsUjCPL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Domain-Driven Design: Tackling Complexity in the Heart of Software&lt;/b&gt;
&lt;br&gt;
by Eric Evans&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321125215%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321125215%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
It's really as good as they say it is! And it's got me thinking... I really enjoy
reading a book that makes me think, I sometimes prefer reading tech books that only
give you concepts to think about. It's up to you to understand those concepts then
find a way to implement them when you see their use is necessary. There's a lot of
great concepts that came from this book, and after seeing them out in the wild in
episodes of DNRTV and source code buried in svn repositories it's all starting to
make sense...
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Entities:&lt;/strong&gt; An object defined primarily by its identity is called an
Entity. 
&lt;li&gt;
&lt;strong&gt;Value Objects:&lt;/strong&gt; An object that describes some characteristic or attribute
but carries no concept of identity. 
&lt;li&gt;
&lt;strong&gt;Aggregates:&lt;/strong&gt; A cluster of associated objects that are treated as a
unit for the purpose of data changes. 
&lt;li&gt;
&lt;strong&gt;Repositories:&lt;/strong&gt; A mechanism for encapsulating storage, retrieval, and
search behavior which emulates a collection of objects. 
&lt;li&gt;
&lt;strong&gt;Services:&lt;/strong&gt; An operation offered as an interface that stands alone
in the model, with no encapsulated state. 
&lt;li&gt;
&lt;strong&gt;Specifications:&lt;/strong&gt; A predicate that determines if an object does or
does not satisfy some criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;font size="1"&gt;*Note: the definitions above are right out of the glossary.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The toughest part to grasp and seems to be the underlying theme of this book is "The
Ubiquitous Language". The tough part is not grasping the "concept" but rather the
implementation. The concept makes a lot of sense, but how you can practically apply
it is a separate story. One that I think takes experience through trial and error.
Time will tell...
&lt;/p&gt;
&lt;p&gt;
Go buy this book, I know I will... until then thank you &lt;a href="http://blog.streamlinelogic.ca/"&gt;Mr.
Adam!&lt;/a&gt;&amp;nbsp;(just in case I can't I put it on my wish list for Santa, he always
pulls through!)
&lt;/p&gt;
&lt;p&gt;
After reading through some examples on specifications and reading through JP's example,
this sparked some ideas in my mind. So I hacked together some code and came up with
this. Let's say I've got a bank of questions, and that each question is part of a
category, and I want to be able to search through the bank of questions...
&lt;/p&gt;
&lt;pre class="code"&gt;[Test]
&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Should_Return_3_Questions_That_Are_Not_Math(
) { &lt;span style="color: rgb(43,145,175)"&gt;IEnumerable&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;IQuestion&lt;/span&gt; &amp;gt;
matches = CreateSut( ).FindAllWhere( &lt;span style="color: rgb(43,145,175)"&gt;Question&lt;/span&gt;.IsIn( &lt;span style="color: rgb(43,145,175)"&gt;Any&lt;/span&gt;.Category
).But( &lt;span style="color: rgb(43,145,175)"&gt;Not&lt;/span&gt;.In( &lt;span style="color: rgb(43,145,175)"&gt;Category&lt;/span&gt;.Math
) ) ); &lt;span style="color: rgb(43,145,175)"&gt;Assert&lt;/span&gt;.AreEqual( 3, GetCountFor(
matches ) ); }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; &lt;blockquote&gt; 
&lt;p&gt;
Notice the use of "But", I&amp;nbsp;wonder if&amp;nbsp;this will&amp;nbsp;catch on... 
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Basically I started looking into creating specification for boolean operations, with
a slightly different take from what the book offered and inspired by &lt;a href="http://www.jpboodhoo.com/blog/EnglandGenericsPresentationSourceCode.aspx"&gt;JP&lt;/a&gt; and &lt;a href="http://www.ayende.com/Blog/archive/2007/06/05/RepositoryltTgt-Syntactic-Sugar-and-DDD.aspx"&gt;Ayende&lt;/a&gt;.
I'm not sure it's the most elegant interface, but I really wanted to be able to make
the client code as readable as possible.
&lt;/p&gt;
&lt;p&gt;
What I ended up with was types like "Is", "Not", "And" &amp;amp; "Or". I'm not sure I'm
completely happy with the end product, but I see potential for extending this further,
and the best part is how readable the code seems to be. I think that excites me more
then anything else... I think I'm just starting to understand this concept of the
"fluent" interface. Not truly implementing it well, seems to be difficult, but fun!
&lt;/p&gt;
&lt;p&gt;
Here's what my Question type turned in too...
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Question&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;IQuestion&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; Question( &lt;span style="color: rgb(43,145,175)"&gt;ICategory&lt;/span&gt; category
) { _category = category; } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ICategory&lt;/span&gt; Category
{ &lt;span style="color: rgb(0,0,255)"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; _category;
} } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ISpecification&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;IQuestion&lt;/span&gt; &amp;gt;
IsIn( &lt;span style="color: rgb(43,145,175)"&gt;ICategory&lt;/span&gt; category ) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Is&lt;/span&gt;.In(
category ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ISpecification&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;IQuestion&lt;/span&gt; &amp;gt;
IsNotIn( &lt;span style="color: rgb(43,145,175)"&gt;ICategory&lt;/span&gt; category ) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Not&lt;/span&gt;.In(
category ); } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ICategory&lt;/span&gt; _category;
} &lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;The Is type looks like... 
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Is&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ISpecification&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;IQuestion&lt;/span&gt; &amp;gt;
In( &lt;span style="color: rgb(43,145,175)"&gt;ICategory&lt;/span&gt; category ) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Specification&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;IQuestion&lt;/span&gt; &amp;gt;( &lt;span style="color: rgb(0,0,255)"&gt;delegate&lt;/span&gt;( &lt;span style="color: rgb(43,145,175)"&gt;IQuestion&lt;/span&gt; question
) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; category.Equals( question.Category
); } ); } } &lt;/pre&gt;
&lt;p&gt;
And the "Not" type looks like...
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Not&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ISpecification&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;IQuestion&lt;/span&gt; &amp;gt;
In( &lt;span style="color: rgb(43,145,175)"&gt;ICategory&lt;/span&gt; category ) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Specification&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43,145,175)"&gt;IQuestion&lt;/span&gt; &amp;gt;( &lt;span style="color: rgb(0,0,255)"&gt;delegate&lt;/span&gt;( &lt;span style="color: rgb(43,145,175)"&gt;IQuestion&lt;/span&gt; question
) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; !category.Equals( question.Category
); } ); } } &lt;/pre&gt;
&lt;p&gt;
To me it still seems that the "Not" and "Is" types shouldn't be responsible for returning
the specification, and that responsibility should belong to the Question, but I'm
just not sure... and it's getting rather late so I should head to bed.
&lt;/p&gt;
&lt;p&gt;
Source is attached!
&lt;/p&gt;
&lt;hints id="hah_hints"&gt;
&lt;/hints&gt;
&lt;a href="http://mokhan.ca/blog/content/binary/PlayingWithSpecifications.zip"&gt;PlayingWithSpecifications.zip
(2.17 MB)&lt;/a&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b86a1dff-7abe-442f-8704-4c3d8f696c45" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=18f5f730-e49e-49f9-ab75-de9bd881a782</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,18f5f730-e49e-49f9-ab75-de9bd881a782.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <blockquote>
          <p>
1. You quickly deliver release 1.0 of a system, but with junky code.
</p>
          <p>
2. You attempt to deliver release 2.0 of the system, but the junky code slows you
down.
</p>
          <p>
3. As you attempt to deliver future releases, you go slower and slower as the junky
code multiplies, until people lose faith in the system, the programmers and even the
process that got everyone into this position.
</p>
        </blockquote>
        <p>
I read it from...
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://g-ec2.images-amazon.com/images/I/01K%2BujmXpML.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Refactoring to Patterns (The Addison-Wesley Signature Series)</b>
                  <br />
by Joshua Kerievsky<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321213351%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321213351%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=18f5f730-e49e-49f9-ab75-de9bd881a782" />
      </body>
      <title>Fast, slow, slower rhythm</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,18f5f730-e49e-49f9-ab75-de9bd881a782.aspx</guid>
      <link>http://mokhan.ca/blog/2007/10/03/Fast+Slow+Slower+Rhythm.aspx</link>
      <pubDate>Wed, 03 Oct 2007 02:18:46 GMT</pubDate>
      <description>&lt;blockquote&gt; 
&lt;p&gt;
1. You quickly deliver release 1.0 of a system, but with junky code.
&lt;/p&gt;
&lt;p&gt;
2. You attempt to deliver release 2.0 of the system, but the junky code slows you
down.
&lt;/p&gt;
&lt;p&gt;
3. As you attempt to deliver future releases, you go slower and slower as the junky
code multiplies, until people lose faith in the system, the programmers and even the
process that got everyone into this position.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I read it from...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://g-ec2.images-amazon.com/images/I/01K%2BujmXpML.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Refactoring to Patterns (The Addison-Wesley Signature Series)&lt;/b&gt;
&lt;br&gt;
by Joshua Kerievsky&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321213351%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321213351%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=18f5f730-e49e-49f9-ab75-de9bd881a782" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=934d45dc-8ab7-4e88-842e-91face231672</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,934d45dc-8ab7-4e88-842e-91face231672.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So recently I started reading...
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/01G7PYAS0DL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Gandhi An Autobiography: The Story of My Experiments With Truth</b>
                  <br />
by Mohandas Karamchand (Mahatma) Gandhi, Mahadev H. Desai<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0807059099%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0807059099%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
And I realized how little I knew about Mahatma Gandhi, although just about everyone
knows the name. Very few know the story, and I was definitely one of those.
</p>
        <p>
I can't really believe how much this man has endured in his life, I'm only about half
way through the book, but he's experienced so much in his life. I really think that
it's the experiences in life help shape who we become, and the more we experience
the better we become.
</p>
        <p>
Here's one quote from the book that stuck out for me... (so far)
</p>
        <blockquote>
          <p>
"It has always been a mystery to me how men can feel themselves honoured by the humiliation
of their fellow beings." - Mahatma Gandhi
</p>
        </blockquote>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=934d45dc-8ab7-4e88-842e-91face231672" />
      </body>
      <title>Conversing With Mahatma</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,934d45dc-8ab7-4e88-842e-91face231672.aspx</guid>
      <link>http://mokhan.ca/blog/2007/09/29/Conversing+With+Mahatma.aspx</link>
      <pubDate>Sat, 29 Sep 2007 14:24:20 GMT</pubDate>
      <description>&lt;p&gt;
So recently I started reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/01G7PYAS0DL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Gandhi An Autobiography: The Story of My Experiments With Truth&lt;/b&gt;
&lt;br&gt;
by Mohandas Karamchand (Mahatma) Gandhi, Mahadev H. Desai&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0807059099%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0807059099%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
And I realized how little I knew about Mahatma&amp;nbsp;Gandhi, although just about everyone
knows the name. Very few know the story, and I was definitely one of those.
&lt;/p&gt;
&lt;p&gt;
I can't really believe how much this man has endured in his life, I'm only about half
way through the book, but he's experienced so much in his life. I really think that
it's the experiences in life help shape who we become, and the more we experience
the better we become.
&lt;/p&gt;
&lt;p&gt;
Here's one quote from the book that stuck out for me... (so far)
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"It has always been a mystery to me how men can feel themselves honoured by the humiliation
of their fellow beings." - Mahatma Gandhi
&lt;/p&gt;
&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=934d45dc-8ab7-4e88-842e-91face231672" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=53374c74-e896-44e7-af6c-76b008734cff</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,53374c74-e896-44e7-af6c-76b008734cff.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I finished reading CLR via C# about a week ago. If you haven't read this book and
enjoy writing C#, you ought to go out right now and get yourself a copy. (I have yet
to purchase a copy for myself, but lucky for me my good ol' pal <a href="http://blog.streamlinelogic.ca/">Mr.
Adam</a> lent me his copy.) This book is amazing, I would have to say that my favorite
chapters were on delegates and events. This is seriously a great book.
</p>
        <blockquote>
          <p>
"When the C# compiler sees the delegate keyword used wherever a reference to a delegate
object is expected, the compiler automatically defines a new private method in
the class... This new method is called an anonymous method because the compiler creates
the name of the method for you automatically, and normally, you wouldn't know it's
name." - Jeffrey Richter, CLR via C#
</p>
        </blockquote>
        <p>
So the below anonymous method would actually get compiled out to a full blown method,
with a name given to it by the compiler.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">return</span>
          <span style="color: rgb(0,0,255)">delegate</span>(T
x, T y) { <span style="color: rgb(0,0,255)">return</span> -comparison(x, y); };</pre>
        <p>
Did you know that you can control event registration and un-registration? 
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">EventAggregator</span>&lt;
T &gt; <span style="color: rgb(0,0,255)">where</span> T : <span style="color: rgb(43,145,175)">EventArgs</span> { <span style="color: rgb(0,0,255)">public</span> EventAggregator(
) { _lock = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,255)">object</span>(
); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">event</span><span style="color: rgb(43,145,175)">EventHandler</span>&lt;
T &gt; NewEvent { <span style="color: rgb(0,0,255)">add</span> { <span style="color: rgb(0,0,255)">lock</span> (
_lock ) { _newEvent += <span style="color: rgb(0,0,255)">value</span>; } } <span style="color: rgb(0,0,255)">remove</span> { <span style="color: rgb(0,0,255)">lock</span> (
_lock ) { _newEvent -= <span style="color: rgb(0,0,255)">value</span>; } } } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> RaiseEvent(
T data ) { _newEvent.Invoke( <span style="color: rgb(0,0,255)">this</span>, data );
} <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(0,0,255)">object</span> _lock; <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(43,145,175)">EventHandler</span>&lt;
T &gt; _newEvent; }</pre>
        <p>
I don't know about you but the above code blew my mind! "add", "remove"... whoa! (poof...
the sound of my mind blowing up!)
</p>
        <p>
I am seriously looking forward the 3rd edition, where I hope Jeffrey Richter talks
about the new additions to the C# compiler in the .NET Framework 3.5. My goodness
what are you still doing sitting there... go by this book...
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/012F1XSYAYL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>CLR via C#, Second Edition (Pro Developer)</b>
                  <br />
by Jeffrey Richter<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0735621632%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0735621632%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=53374c74-e896-44e7-af6c-76b008734cff" />
      </body>
      <title>CLeaRly Understanding C#</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,53374c74-e896-44e7-af6c-76b008734cff.aspx</guid>
      <link>http://mokhan.ca/blog/2007/09/25/CLeaRly+Understanding+C.aspx</link>
      <pubDate>Tue, 25 Sep 2007 02:45:49 GMT</pubDate>
      <description>&lt;p&gt;
I finished reading CLR via C# about a week ago. If you haven't read this book and
enjoy writing C#, you ought to go out right now and get yourself a copy. (I have yet
to purchase a copy for myself, but lucky for me my good ol' pal &lt;a href="http://blog.streamlinelogic.ca/"&gt;Mr.
Adam&lt;/a&gt; lent me his copy.) This book is amazing, I would have to say that my favorite
chapters were on delegates and events. This is seriously a great book.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"When the C# compiler sees the delegate keyword used wherever a reference to a delegate
object&amp;nbsp;is expected, the compiler automatically defines a new private method in
the class... This new method is called an anonymous method because the compiler creates
the name of the method for you automatically, and normally, you wouldn't know it's
name." - Jeffrey Richter, CLR via C#
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
So the below anonymous method would actually get compiled out to a full blown method,
with a name given to it by the compiler.
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;delegate&lt;/span&gt;(T
x, T y) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; -comparison(x, y); };&lt;/pre&gt;
&lt;p&gt;
Did you know that you can control event registration and un-registration? 
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EventAggregator&lt;/span&gt;&amp;lt;
T &amp;gt; &lt;span style="color: rgb(0,0,255)"&gt;where&lt;/span&gt; T : &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; EventAggregator(
) { _lock = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt;(
); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;event&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EventHandler&lt;/span&gt;&amp;lt;
T &amp;gt; NewEvent { &lt;span style="color: rgb(0,0,255)"&gt;add&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;lock&lt;/span&gt; (
_lock ) { _newEvent += &lt;span style="color: rgb(0,0,255)"&gt;value&lt;/span&gt;; } } &lt;span style="color: rgb(0,0,255)"&gt;remove&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;lock&lt;/span&gt; (
_lock ) { _newEvent -= &lt;span style="color: rgb(0,0,255)"&gt;value&lt;/span&gt;; } } } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; RaiseEvent(
T data ) { _newEvent.Invoke( &lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, data );
} &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt; _lock; &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;EventHandler&lt;/span&gt;&amp;lt;
T &amp;gt; _newEvent; }&lt;/pre&gt;
&lt;p&gt;
I don't know about you but the above code blew my mind! "add", "remove"... whoa! (poof...
the sound of my mind blowing up!)
&lt;/p&gt;
&lt;p&gt;
I am seriously looking forward the 3rd edition, where I hope Jeffrey Richter talks
about the new additions to the C# compiler in the .NET Framework 3.5. My goodness
what are you still doing sitting there... go by this book...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/012F1XSYAYL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;CLR via C#, Second Edition (Pro Developer)&lt;/b&gt;
&lt;br&gt;
by Jeffrey Richter&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0735621632%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0735621632%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=53374c74-e896-44e7-af6c-76b008734cff" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=fd0f2d79-b7aa-4c2b-91f9-c1d8c5203fe2</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,fd0f2d79-b7aa-4c2b-91f9-c1d8c5203fe2.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently came across a problem, and I thought I would try to flex some of my developer
muscle to try to solve it. The problem reads as follows:
</p>
        <blockquote>
          <p>
Basic sales tax is applicable at a rate of 10% on all goods, except books,<br />
food, and medical products that are exempt. Import duty is an additional<br />
sales tax applicable on all imported goods at a rate of 5%, with no<br />
exemptions. 
</p>
          <p>
When I purchase items I receive a receipt which lists the name of all the<br />
items and their price (including tax), finishing with the total cost of the<br />
items, and the total amounts of sales taxes paid.  The rounding rules for<br />
sales tax are that for a tax rate of n%, a shelf price of p contains<br />
(np/100 rounded up to the nearest 0.05) amount of sales tax. 
</p>
          <p>
Write an application that prints out the receipt details for these shopping<br />
baskets...<br />
INPUT:_ 
</p>
          <p>
Input 1:<br />
1 book at 12.49<br />
1 music CD at 14.99<br />
1 chocolate bar at 0.85 
</p>
          <p>
Input 2:<br />
1 imported box of chocolates at 10.00<br />
1 imported bottle of perfume at 47.50 
</p>
          <p>
Input 3:<br />
1 imported bottle of perfume at 27.99<br />
1 bottle of perfume at 18.99<br />
1 packet of headache pills at 9.75<br />
1 box of imported chocolates at 11.25 
</p>
          <p>
OUTPUT 
</p>
          <p>
Output 1:<br />
1 book : 12.49<br />
1 music CD: 16.49<br />
1 chocolate bar: 0.85<br />
Sales Taxes: 1.50<br />
Total: 29.83 
</p>
          <p>
Output 2:<br />
1 imported box of chocolates: 10.50<br />
1 imported bottle of perfume: 54.65<br />
Sales Taxes: 7.65<br />
Total: 65.15 
</p>
          <p>
Output 3:<br />
1 imported bottle of perfume: 32.19<br />
1 bottle of perfume: 20.89<br />
1 packet of headache pills: 9.75<br />
1 imported box of chocolates: 11.85<br />
Sales Taxes: 6.70<br />
Total: 74.68<br />
==========
</p>
        </blockquote>
        <p>
To solve this problem I used a composite to calculate taxes. The "TaxComposite" type
allows you to bundle several different taxes all in one type. So when calculating
taxes, the calculation with iterate through all the taxes and add the calculated tax
and return the total value. 
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span>
          <span style="color: rgb(0, 0, 255);">class</span>
          <span style="color: rgb(43, 145, 175);">TaxComposite</span> : <span style="color: rgb(43, 145, 175);">ITax</span> { <span style="color: rgb(0, 0, 255);">public</span> TaxComposite( <span style="color: rgb(0, 0, 255);">params</span><span style="color: rgb(43, 145, 175);">ITax</span>[]
taxes ) : <span style="color: rgb(0, 0, 255);">this</span>( <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">List</span>&lt; <span style="color: rgb(43, 145, 175);">ITax</span> &gt;(
taxes ) ) {} <span style="color: rgb(0, 0, 255);">public</span> TaxComposite( <span style="color: rgb(43, 145, 175);">IEnumerable</span>&lt; <span style="color: rgb(43, 145, 175);">ITax</span> &gt;
taxes ) { _taxes = <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">List</span>&lt; <span style="color: rgb(43, 145, 175);">ITax</span> &gt;(
taxes ); _amount = CalculateAmount( ); _type = CalculateType( ); } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">double</span> Amount
{ <span style="color: rgb(0, 0, 255);">get</span> { <span style="color: rgb(0, 0, 255);">return</span> _amount;
} } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(43, 145, 175);">TaxTypes</span> Type
{ <span style="color: rgb(0, 0, 255);">get</span> { <span style="color: rgb(0, 0, 255);">return</span> _type;
} } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(43, 145, 175);">IMoney</span> CalculateTaxFor( <span style="color: rgb(43, 145, 175);">IMoney</span> price
) { <span style="color: rgb(0, 0, 255);">return</span> CalculateTaxFor( price, <span style="color: rgb(43, 145, 175);">RoundingDelegateFactory</span>.RoundToNearestTenCents
); } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(43, 145, 175);">IMoney</span> CalculateTaxFor( <span style="color: rgb(43, 145, 175);">IMoney</span> price, <span style="color: rgb(43, 145, 175);">RoundingStrategy</span> round
) { <span style="color: rgb(43, 145, 175);">IMoney</span> total = <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">Money</span>(
); Summary( <span style="color: rgb(0, 0, 255);">delegate</span>( <span style="color: rgb(43, 145, 175);">ITax</span> tax
) { total = total.Add( tax.CalculateTaxFor( price, round ) ); } ); <span style="color: rgb(0, 0, 255);">return</span> total;
} <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 255);">double</span> CalculateAmount(
) { <span style="color: rgb(0, 0, 255);">double</span> amount = 0d; Summary( <span style="color: rgb(0, 0, 255);">delegate</span>( <span style="color: rgb(43, 145, 175);">ITax</span> tax
) { amount += tax.Amount; } ); <span style="color: rgb(0, 0, 255);">return</span> amount;
} <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(43, 145, 175);">TaxTypes</span> CalculateType(
) { <span style="color: rgb(43, 145, 175);">TaxTypes</span> type = <span style="color: rgb(43, 145, 175);">TaxTypes</span>.None;
Summary( <span style="color: rgb(0, 0, 255);">delegate</span>( <span style="color: rgb(43, 145, 175);">ITax</span> tax
) { type = type | tax.Type; } ); <span style="color: rgb(0, 0, 255);">return</span> type;
} <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 255);">void</span> Summary( <span style="color: rgb(43, 145, 175);">Action</span>&lt; <span style="color: rgb(43, 145, 175);">ITax</span> &gt;
toDo ) { <span style="color: rgb(0, 0, 255);">foreach</span> ( <span style="color: rgb(43, 145, 175);">ITax</span> tax <span style="color: rgb(0, 0, 255);">in</span> _taxes
) { toDo( tax ); } } <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 255);">readonly</span><span style="color: rgb(43, 145, 175);">IList</span>&lt; <span style="color: rgb(43, 145, 175);">ITax</span> &gt;
_taxes; <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 255);">readonly</span><span style="color: rgb(0, 0, 255);">double</span> _amount; <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 255);">readonly</span><span style="color: rgb(43, 145, 175);">TaxTypes</span> _type;
}</pre>
        <blockquote>
          <p>
"The Composite Pattern allows you to compose objects into tree structures to represent
part-whole hierarchies. Composite lets clients treat individual objects and compositions
of objects uniformly." - Head First Design Patterns
</p>
        </blockquote>
        <p>
I used a TaxFactory type to construct the TaxComposite type which gathers all
the taxes that match a specified predicate and injects it into the TaxComposite constructor.
It looks like...
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span>
          <span style="color: rgb(0, 0, 255);">static</span>
          <span style="color: rgb(0, 0, 255);">class</span>
          <span style="color: rgb(43, 145, 175);">TaxFactory</span> { <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(43, 145, 175);">ITax</span> Create( <span style="color: rgb(43, 145, 175);">TaxTypes</span> forTaxes
) { <span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">TaxComposite</span>( <span style="color: rgb(43, 145, 175);">Taxes</span>.FindBy( <span style="color: rgb(0, 0, 255);">delegate</span>( <span style="color: rgb(43, 145, 175);">ITax</span> tax
) { <span style="color: rgb(0, 0, 255);">return</span> ( tax.Type &amp; forTaxes )
== tax.Type; } ) ); }</pre>
        <p>
The tax type is an enum that uses the flags attribute so that I can enable different bits
for different taxes. 
</p>
        <pre class="code">    [<span style="color: rgb(43, 145, 175);">Flags</span>] <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">enum</span><span style="color: rgb(43, 145, 175);">TaxTypes</span> {
None = 0x00, Sales = 0x01, Import = 0x02 }</pre>
        <p>
Taxes is a static type that contains different types of taxes. The FindBy method allows
for different strategies to be passed into to gather different types of taxes based
on different critera. The above example returns all the taxes that are enabled in
the "forTaxes" argument. FindBy is defined like...
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span>
          <span style="color: rgb(0, 0, 255);">static</span>
          <span style="color: rgb(43, 145, 175);">IEnumerable</span>&lt; <span style="color: rgb(43, 145, 175);">ITax</span> &gt;
FindBy( <span style="color: rgb(43, 145, 175);">Predicate</span>&lt; <span style="color: rgb(43, 145, 175);">ITax</span> &gt;
condition ) { <span style="color: rgb(0, 0, 255);">foreach</span> ( <span style="color: rgb(43, 145, 175);">ITax</span> tax <span style="color: rgb(0, 0, 255);">in</span> taxes
) { <span style="color: rgb(0, 0, 255);">if</span> ( condition( tax ) ) { <span style="color: rgb(0, 0, 255);">yield</span><span style="color: rgb(0, 0, 255);">return</span> tax;
} } }</pre>
        <p>
I'm not sure if this is the most flexible design, but if i need to make changes to
tax rates I can do that in one spot. The only catch is that it requires a re-compile
to take a effect. In a full blown implementation I may want to consider using a "service"
to retrieve the tax rates. Also, in this implementation in order to add new taxes
I have to added it too 2 different locations. The first is the TaxTypes enum and the
second is the Taxes static holder class. This leaves a bit of a smell...
</p>
        <p>
          <table unselectable="on" border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/115M5YwkVnL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Head First Design Patterns (Head First)</b>
                  <br />
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596007124%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596007124%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=fd0f2d79-b7aa-4c2b-91f9-c1d8c5203fe2" />
      </body>
      <title>SALES TAXES</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,fd0f2d79-b7aa-4c2b-91f9-c1d8c5203fe2.aspx</guid>
      <link>http://mokhan.ca/blog/2007/09/25/SALES+TAXES.aspx</link>
      <pubDate>Tue, 25 Sep 2007 02:07:23 GMT</pubDate>
      <description>&lt;p&gt;
I recently came across a problem, and I thought I would try to flex some of my developer
muscle to try to solve it. The problem reads as follows:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Basic sales tax is applicable at a rate of 10% on all goods, except books,&lt;br&gt;
food, and medical products that are exempt. Import duty is an additional&lt;br&gt;
sales tax applicable on all imported goods at a rate of 5%, with no&lt;br&gt;
exemptions. 
&lt;/p&gt;
&lt;p&gt;
When I purchase items I receive a receipt which lists the name of all the&lt;br&gt;
items and their price (including tax), finishing with the total cost of the&lt;br&gt;
items, and the total amounts of sales taxes paid.&amp;nbsp; The rounding rules for&lt;br&gt;
sales tax are that for a tax rate of n%, a shelf price of p contains&lt;br&gt;
(np/100 rounded up to the nearest 0.05) amount of sales tax. 
&lt;/p&gt;
&lt;p&gt;
Write an application that prints out the receipt details for these shopping&lt;br&gt;
baskets...&lt;br&gt;
INPUT:_ 
&lt;/p&gt;
&lt;p&gt;
Input 1:&lt;br&gt;
1 book at 12.49&lt;br&gt;
1 music CD at 14.99&lt;br&gt;
1 chocolate bar at 0.85 
&lt;/p&gt;
&lt;p&gt;
Input 2:&lt;br&gt;
1 imported box of chocolates at 10.00&lt;br&gt;
1 imported bottle of perfume at 47.50 
&lt;/p&gt;
&lt;p&gt;
Input 3:&lt;br&gt;
1 imported bottle of perfume at 27.99&lt;br&gt;
1 bottle of perfume at 18.99&lt;br&gt;
1 packet of headache pills at 9.75&lt;br&gt;
1 box of imported chocolates at 11.25 
&lt;/p&gt;
&lt;p&gt;
OUTPUT 
&lt;/p&gt;
&lt;p&gt;
Output 1:&lt;br&gt;
1 book : 12.49&lt;br&gt;
1 music CD: 16.49&lt;br&gt;
1 chocolate bar: 0.85&lt;br&gt;
Sales Taxes: 1.50&lt;br&gt;
Total: 29.83 
&lt;/p&gt;
&lt;p&gt;
Output 2:&lt;br&gt;
1 imported box of chocolates: 10.50&lt;br&gt;
1 imported bottle of perfume: 54.65&lt;br&gt;
Sales Taxes: 7.65&lt;br&gt;
Total: 65.15 
&lt;/p&gt;
&lt;p&gt;
Output 3:&lt;br&gt;
1 imported bottle of perfume: 32.19&lt;br&gt;
1 bottle of perfume: 20.89&lt;br&gt;
1 packet of headache pills: 9.75&lt;br&gt;
1 imported box of chocolates: 11.85&lt;br&gt;
Sales Taxes: 6.70&lt;br&gt;
Total: 74.68&lt;br&gt;
==========
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
To solve this problem I used a composite to calculate taxes. The "TaxComposite" type
allows you to bundle several different taxes all in one type. So when calculating
taxes, the calculation with iterate through all the taxes and add the calculated tax
and return the total value. 
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;TaxComposite&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; TaxComposite( &lt;span style="color: rgb(0, 0, 255);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt;[]
taxes ) : &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;( &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;List&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; &amp;gt;(
taxes ) ) {} &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; TaxComposite( &lt;span style="color: rgb(43, 145, 175);"&gt;IEnumerable&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; &amp;gt;
taxes ) { _taxes = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;List&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; &amp;gt;(
taxes ); _amount = CalculateAmount( ); _type = CalculateType( ); } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; Amount
{ &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _amount;
} } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;TaxTypes&lt;/span&gt; Type
{ &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _type;
} } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IMoney&lt;/span&gt; CalculateTaxFor( &lt;span style="color: rgb(43, 145, 175);"&gt;IMoney&lt;/span&gt; price
) { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; CalculateTaxFor( price, &lt;span style="color: rgb(43, 145, 175);"&gt;RoundingDelegateFactory&lt;/span&gt;.RoundToNearestTenCents
); } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IMoney&lt;/span&gt; CalculateTaxFor( &lt;span style="color: rgb(43, 145, 175);"&gt;IMoney&lt;/span&gt; price, &lt;span style="color: rgb(43, 145, 175);"&gt;RoundingStrategy&lt;/span&gt; round
) { &lt;span style="color: rgb(43, 145, 175);"&gt;IMoney&lt;/span&gt; total = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Money&lt;/span&gt;(
); Summary( &lt;span style="color: rgb(0, 0, 255);"&gt;delegate&lt;/span&gt;( &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; tax
) { total = total.Add( tax.CalculateTaxFor( price, round ) ); } ); &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; total;
} &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; CalculateAmount(
) { &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; amount = 0d; Summary( &lt;span style="color: rgb(0, 0, 255);"&gt;delegate&lt;/span&gt;( &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; tax
) { amount += tax.Amount; } ); &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; amount;
} &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;TaxTypes&lt;/span&gt; CalculateType(
) { &lt;span style="color: rgb(43, 145, 175);"&gt;TaxTypes&lt;/span&gt; type = &lt;span style="color: rgb(43, 145, 175);"&gt;TaxTypes&lt;/span&gt;.None;
Summary( &lt;span style="color: rgb(0, 0, 255);"&gt;delegate&lt;/span&gt;( &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; tax
) { type = type | tax.Type; } ); &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; type;
} &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Summary( &lt;span style="color: rgb(43, 145, 175);"&gt;Action&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; &amp;gt;
toDo ) { &lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; ( &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; tax &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; _taxes
) { toDo( tax ); } } &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IList&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; &amp;gt;
_taxes; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; _amount; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;TaxTypes&lt;/span&gt; _type;
}&lt;/pre&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"The Composite Pattern allows you to compose objects into tree structures to represent
part-whole hierarchies. Composite lets clients treat individual objects and compositions
of objects uniformly." - Head First Design Patterns
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I used a TaxFactory type&amp;nbsp;to construct the TaxComposite type which gathers all
the taxes that match a specified predicate and injects it into the TaxComposite constructor.
It looks like...
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;TaxFactory&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; Create( &lt;span style="color: rgb(43, 145, 175);"&gt;TaxTypes&lt;/span&gt; forTaxes
) { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;TaxComposite&lt;/span&gt;( &lt;span style="color: rgb(43, 145, 175);"&gt;Taxes&lt;/span&gt;.FindBy( &lt;span style="color: rgb(0, 0, 255);"&gt;delegate&lt;/span&gt;( &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; tax
) { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; ( tax.Type &amp;amp; forTaxes )
== tax.Type; } ) ); }&lt;/pre&gt;
&lt;p&gt;
The tax type is an enum that uses the flags attribute so that I can enable different&amp;nbsp;bits
for different taxes. 
&lt;/p&gt;
&lt;pre class="code"&gt;    [&lt;span style="color: rgb(43, 145, 175);"&gt;Flags&lt;/span&gt;] &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;enum&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;TaxTypes&lt;/span&gt; {
None = 0x00, Sales = 0x01, Import = 0x02 }&lt;/pre&gt;
&lt;p&gt;
Taxes is a static type that contains different types of taxes. The FindBy method allows
for different strategies to be passed into to gather different types of taxes based
on different critera. The above example returns all the taxes that are enabled in
the "forTaxes" argument. FindBy is defined like...
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IEnumerable&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; &amp;gt;
FindBy( &lt;span style="color: rgb(43, 145, 175);"&gt;Predicate&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; &amp;gt;
condition ) { &lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; ( &lt;span style="color: rgb(43, 145, 175);"&gt;ITax&lt;/span&gt; tax &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; taxes
) { &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; ( condition( tax ) ) { &lt;span style="color: rgb(0, 0, 255);"&gt;yield&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; tax;
} } }&lt;/pre&gt;
&lt;p&gt;
I'm not sure if this is the most flexible design, but if i need to make changes to
tax rates I can do that in one spot. The only catch is that it requires a re-compile
to take a effect. In a full blown implementation I may want to consider using a "service"
to retrieve the tax rates. Also, in this implementation in order to add new taxes
I have to added it too 2 different locations. The first is the TaxTypes enum and the
second is the Taxes static holder class. This leaves a bit of a smell...
&lt;/p&gt;
&lt;p&gt;
&lt;table unselectable="on" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/115M5YwkVnL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Head First Design Patterns (Head First)&lt;/b&gt;
&lt;br&gt;
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596007124%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596007124%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=fd0f2d79-b7aa-4c2b-91f9-c1d8c5203fe2" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
      <category>Design Patterns</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=09d3a842-ae45-4adc-9bf6-8e8afe92de20</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,09d3a842-ae45-4adc-9bf6-8e8afe92de20.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you take a look at the following line, you will probably recognize it as the signature
for an event handler.
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span>
          <span style="color: rgb(0, 0, 255);">void</span> Handler( <span style="color: rgb(0, 0, 255);">object</span> sender, <span style="color: rgb(43, 145, 175);">EventArgs</span> e
) {</pre>
        <p>
The reason why event handlers are defined with this signature is because it matches
the signature of the EventHandler delegate which looks like this:
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span>
          <span style="color: rgb(0, 0, 255);">delegate</span>
          <span style="color: rgb(0, 0, 255);">void</span>
          <span style="color: rgb(43, 145, 175);">EventHandler</span>(<span style="color: rgb(0, 0, 255);">object</span> sender, <span style="color: rgb(43, 145, 175);">EventArgs</span> e);</pre>
        <p>
So when you're registering an event handler to an event. You're adding a delegate
to the internal list of delegates. (Think of a type safe array of function pointers.)
So when the event is raised, each method in the list of delegates is raised, in the
same order as they were registered in.
</p>
        <p>
The following line:
</p>
        <pre class="code">container.MyEvent += <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">PlayingWithEventHandlers</span>( <span style="color: rgb(43, 145, 175);">Console</span>.Out.WriteLine
).Handler;</pre>
        <p>
Expands out to something like this...
</p>
        <pre class="code">
          <span style="color: rgb(43, 145, 175);">PlayingWithEventHandlers</span> handlers
= <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">PlayingWithEventHandlers</span>( <span style="color: rgb(43, 145, 175);">Console</span>.Out.WriteLine
); <span style="color: rgb(43, 145, 175);">MulticastDelegate</span> multicastDelegate
= <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">MulticastDelegate</span>(
handlers, <span style="color: rgb(163, 21, 21);">"Handler"</span> );</pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>You'll find that the MulticastDelegate
constructor is protected so this code wont actually compile. Also, the event delegate
is combining the newly added delegate that is registering for the event.
</p>
        <p>
The following example uses 3 different delegates defined in the .NET Framework.
</p>
        <pre class="code">
          <span style="color: rgb(0, 128, 0);">//public delegate void
EventHandler(object sender, EventArgs e); </span>
          <span style="color: rgb(0, 128, 0);">//public
delegate void TimerCallback(object state); </span>
          <span style="color: rgb(0, 128, 0);">//public
delegate void Action&lt;T&gt;(T obj); </span>
          <span style="color: rgb(0, 0, 255);">public</span>
          <span style="color: rgb(0, 0, 255);">class</span>
          <span style="color: rgb(43, 145, 175);">PlayingWithEventHandlers</span> { <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 255);">readonly</span><span style="color: rgb(43, 145, 175);">Action</span>&lt; <span style="color: rgb(0, 0, 255);">string</span> &gt;
_action; <span style="color: rgb(0, 0, 255);">public</span> PlayingWithEventHandlers( <span style="color: rgb(43, 145, 175);">Action</span>&lt; <span style="color: rgb(0, 0, 255);">string</span> &gt;
action ) { _action = action; } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">void</span> Handler( <span style="color: rgb(0, 0, 255);">object</span> sender, <span style="color: rgb(43, 145, 175);">EventArgs</span> e
) { _action( ( <span style="color: rgb(0, 0, 255);">string</span> )sender ); } } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(43, 145, 175);">MyEventContainer</span> { <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(43, 145, 175);">Timer</span> _timer; <span style="color: rgb(0, 0, 255);">public</span> MyEventContainer(
) { _timer = <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">Timer</span>( <span style="color: rgb(0, 0, 255);">delegate</span>( <span style="color: rgb(0, 0, 255);">object</span> state
) { MyEvent.Invoke( state, <span style="color: rgb(43, 145, 175);">EventArgs</span>.Empty
); }, <span style="color: rgb(163, 21, 21);">"Tick"</span>, 0, 5000 ); } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">event</span><span style="color: rgb(43, 145, 175);">EventHandler</span> MyEvent;
} <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(43, 145, 175);">Bootstrap</span> { <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 255);">void</span> Main(
) { <span style="color: rgb(43, 145, 175);">MyEventContainer</span> container = <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">MyEventContainer</span>(
); container.MyEvent += <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">PlayingWithEventHandlers</span>( <span style="color: rgb(43, 145, 175);">Console</span>.Out.WriteLine
).Handler; <span style="color: rgb(43, 145, 175);">Console</span>.In.ReadLine( );
} }</pre>
        <p>
One of the benefits of using delegates that you can inline an anonymous delegate.
The above line where the an instance of the Timer class is constructed could be re-written
like...
</p>
        <pre class="code">_timer = <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">Timer</span>( <span style="color: rgb(0, 0, 255);">delegate</span> {
MyEvent.Invoke( <span style="color: rgb(163, 21, 21);">"Tick"</span>, <span style="color: rgb(43, 145, 175);">EventArgs</span>.Empty
); }, <span style="color: rgb(0, 0, 255);">null</span>, 0, 5000 );</pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>The TimerCallBack's input parameter
"state" is still passed to the delegate but the C# compiler allows for this shorthand
which ignores the input parameter. The same code could also be re-written as...
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span> MyEventContainer(
) { _timer = <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">Timer</span>(
TimerClickHandler, <span style="color: rgb(163, 21, 21);">"Tick"</span>, 0, 5000 );
} <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">void</span> TimerClickHandler( <span style="color: rgb(0, 0, 255);">object</span> state
) { MyEvent.Invoke( state, <span style="color: rgb(43, 145, 175);">EventArgs</span>.Empty
); }</pre>
        <p>
This version creates a new method called "TimerClickHandler" that matches the "<a href="http://msdn2.microsoft.com/en-us/library/system.threading.timercallback.aspx">TimerCallback</a>"
delegate signature. Delegates can be quite fun... almost as fun as tables of function
pointers in C. 
</p>
        <p>
For more information check out...
</p>
        <p>
          <table unselectable="on" border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/012F1XSYAYL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>CLR via C#, Second Edition (Pro Developer)</b>
                  <br />
by Jeffrey Richter<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0735621632%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0735621632%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <hints id="hah_hints">
        </hints>
        <a href="http://mokhan.ca/blog/content/binary/EventHandler.txt">EventHandler.txt (1.22
KB)</a>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=09d3a842-ae45-4adc-9bf6-8e8afe92de20" />
      </body>
      <title>Keeping It Real With Delegates</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,09d3a842-ae45-4adc-9bf6-8e8afe92de20.aspx</guid>
      <link>http://mokhan.ca/blog/2007/09/11/Keeping+It+Real+With+Delegates.aspx</link>
      <pubDate>Tue, 11 Sep 2007 18:46:21 GMT</pubDate>
      <description>&lt;p&gt;
If you take a look at the following line, you will probably recognize it as the signature
for an event handler.
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Handler( &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e
) {&lt;/pre&gt;
&lt;p&gt;
The reason why event handlers are defined with this signature is because it matches
the signature of the EventHandler delegate which looks like this:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;delegate&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;EventHandler&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e);&lt;/pre&gt;
&lt;p&gt;
So when you're&amp;nbsp;registering an event handler to an event. You're adding a delegate
to the internal list of delegates. (Think of a type safe array of function pointers.)
So when the event is raised, each method in the list of delegates is raised, in the
same order as they were registered in.
&lt;/p&gt;
&lt;p&gt;
The following line:
&lt;/p&gt;
&lt;pre class="code"&gt;container.MyEvent += &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;PlayingWithEventHandlers&lt;/span&gt;( &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.Out.WriteLine
).Handler;&lt;/pre&gt;
&lt;p&gt;
Expands out to something like this...
&lt;/p&gt;
&lt;pre class="code"&gt;            &lt;span style="color: rgb(43, 145, 175);"&gt;PlayingWithEventHandlers&lt;/span&gt; handlers
= &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;PlayingWithEventHandlers&lt;/span&gt;( &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.Out.WriteLine
); &lt;span style="color: rgb(43, 145, 175);"&gt;MulticastDelegate&lt;/span&gt; multicastDelegate
= &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;MulticastDelegate&lt;/span&gt;(
handlers, &lt;span style="color: rgb(163, 21, 21);"&gt;"Handler"&lt;/span&gt; );&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;You'll find that the MulticastDelegate
constructor is protected so this code wont actually compile. Also, the event delegate
is combining the newly added delegate that is registering for the event.
&lt;/p&gt;
&lt;p&gt;
The following example uses&amp;nbsp;3 different delegates defined in the .NET Framework.
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;//public delegate void
EventHandler(object sender, EventArgs e); &lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;//public
delegate void TimerCallback(object state); &lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;//public
delegate void Action&amp;lt;T&amp;gt;(T obj); &lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;PlayingWithEventHandlers&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Action&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; &amp;gt;
_action; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; PlayingWithEventHandlers( &lt;span style="color: rgb(43, 145, 175);"&gt;Action&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; &amp;gt;
action ) { _action = action; } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Handler( &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e
) { _action( ( &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; )sender ); } } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;MyEventContainer&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Timer&lt;/span&gt; _timer; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; MyEventContainer(
) { _timer = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Timer&lt;/span&gt;( &lt;span style="color: rgb(0, 0, 255);"&gt;delegate&lt;/span&gt;( &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; state
) { MyEvent.Invoke( state, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt;.Empty
); }, &lt;span style="color: rgb(163, 21, 21);"&gt;"Tick"&lt;/span&gt;, 0, 5000 ); } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;event&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;EventHandler&lt;/span&gt; MyEvent;
} &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Bootstrap&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(
) { &lt;span style="color: rgb(43, 145, 175);"&gt;MyEventContainer&lt;/span&gt; container = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;MyEventContainer&lt;/span&gt;(
); container.MyEvent += &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;PlayingWithEventHandlers&lt;/span&gt;( &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.Out.WriteLine
).Handler; &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.In.ReadLine( );
} }&lt;/pre&gt;
&lt;p&gt;
One of the benefits of using delegates that you can inline an anonymous delegate.
The above line where the an instance of the Timer class is constructed could be re-written
like...
&lt;/p&gt;
&lt;pre class="code"&gt;_timer = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Timer&lt;/span&gt;( &lt;span style="color: rgb(0, 0, 255);"&gt;delegate&lt;/span&gt; {
MyEvent.Invoke( &lt;span style="color: rgb(163, 21, 21);"&gt;"Tick"&lt;/span&gt;, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt;.Empty
); }, &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;, 0, 5000 );&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;The TimerCallBack's input parameter
"state" is still passed to the delegate but the C# compiler allows for this shorthand
which ignores the input parameter. The same code could also be re-written as...
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; MyEventContainer(
) { _timer = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Timer&lt;/span&gt;(
TimerClickHandler, &lt;span style="color: rgb(163, 21, 21);"&gt;"Tick"&lt;/span&gt;, 0, 5000 );
} &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; TimerClickHandler( &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; state
) { MyEvent.Invoke( state, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt;.Empty
); }&lt;/pre&gt;
&lt;p&gt;
This version creates a new method called "TimerClickHandler" that matches the "&lt;a href="http://msdn2.microsoft.com/en-us/library/system.threading.timercallback.aspx"&gt;TimerCallback&lt;/a&gt;"
delegate signature. Delegates can be quite fun... almost as fun as tables of function
pointers in C. 
&lt;/p&gt;
&lt;p&gt;
For more information check out...
&lt;/p&gt;
&lt;p&gt;
&lt;table unselectable="on" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/012F1XSYAYL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;CLR via C#, Second Edition (Pro Developer)&lt;/b&gt;
&lt;br&gt;
by Jeffrey Richter&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0735621632%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0735621632%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;hints id="hah_hints"&gt;
&lt;/hints&gt;
&lt;a href="http://mokhan.ca/blog/content/binary/EventHandler.txt"&gt;EventHandler.txt (1.22
KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=09d3a842-ae45-4adc-9bf6-8e8afe92de20" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=e5580370-31a1-411c-8a28-6c727ec7c193</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,e5580370-31a1-411c-8a28-6c727ec7c193.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>
            <a href="http://en.wikipedia.org/wiki/Open/closed_principle">The Open-Closed
Principle (OCP):</a>
          </strong> Classes should be open for extension, and closed for
modification.
</p>
        <p>
          <strong>
            <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">The Don't Repeat
Yourself Principle (DRY):</a>
          </strong> Avoid duplicate code by abstracting out things
that are common and placing those things in a single location.
</p>
        <p>
          <strong>
            <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">The
Single Responsibility Principle (SRP):</a>
          </strong> Every object in your system should
have a single responsibility, and all the objects services should be focused carrying
out that single responsibility.
</p>
        <p>
          <strong>
            <a href="http://en.wikipedia.org/wiki/Liskov_substitution_principle">The Liskov
Substitution Principle (LSP):</a>
          </strong> Subtypes must be substitutable for their
base types. (The LSP is all about well-designed inheritance.)
</p>
        <p>
          <a href="http://en.wikipedia.org/wiki/Hollywood_Principle">The Hollywood Principle:</a> Don't
call us, we'll call you.
</p>
        <p>
          <a href="http://en.wikipedia.org/wiki/Law_of_Demeter">The Law of Demeter (The principle
of least knowledge):</a> Only talk to your immediate friends.
</p>
        <p>
          <strong>
            <a href="http://en.wikipedia.org/wiki/Delegation">Delegation</a>
          </strong> is
when you hand over the responsibility for a particular task to another class or method.
</p>
        <p>
          <strong>
            <a href="http://en.wikipedia.org/wiki/Object_composition">Composition</a>
          </strong> allows
you to use behavior from a family of other classes, and to change that behavior at
runtime.
</p>
        <p>
          <strong>
            <a href="http://en.wikipedia.org/wiki/Object_composition#Aggregation">Aggregation</a>
          </strong> is
when one class is used as part of another class, but still exists outside of that
other class.
</p>
        <p>
Encapsulate what varies.
</p>
        <p>
Favor composition over inheritance.
</p>
        <p>
Program to interfaces, not implementations.
</p>
        <p>
Strive for loosely coupled designs between objects that interact.
</p>
        <p>
Depend on abstractions. Do not depend on concrete classes.
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/1115DCWP81L.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Head First Object-Oriented Analysis and Design: A Brain Friendly Guide to OOA&amp;D
(Head First)</b>
                  <br />
by Brett D. McLaughlin, Gary Pollice, Dave West<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596008678%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596008678%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=e5580370-31a1-411c-8a28-6c727ec7c193" />
      </body>
      <title>Design Principles</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,e5580370-31a1-411c-8a28-6c727ec7c193.aspx</guid>
      <link>http://mokhan.ca/blog/2007/09/09/Design+Principles.aspx</link>
      <pubDate>Sun, 09 Sep 2007 23:12:54 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt;&lt;a href="http://en.wikipedia.org/wiki/Open/closed_principle"&gt;The Open-Closed
Principle (OCP):&lt;/a&gt;&lt;/strong&gt; Classes should be open for extension, and closed for
modification.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;The Don't Repeat
Yourself Principle (DRY):&lt;/a&gt;&lt;/strong&gt; Avoid duplicate code by abstracting out things
that are common and placing those things in a single location.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://en.wikipedia.org/wiki/Single_responsibility_principle"&gt;The
Single Responsibility Principle (SRP):&lt;/a&gt;&lt;/strong&gt; Every object in your system should
have a single responsibility, and all the objects services should be focused carrying
out that single responsibility.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://en.wikipedia.org/wiki/Liskov_substitution_principle"&gt;The Liskov
Substitution Principle (LSP):&lt;/a&gt;&lt;/strong&gt; Subtypes must be substitutable for their
base types. (The LSP is all about well-designed inheritance.)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://en.wikipedia.org/wiki/Hollywood_Principle"&gt;The Hollywood Principle:&lt;/a&gt; Don't
call us, we'll call you.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://en.wikipedia.org/wiki/Law_of_Demeter"&gt;The Law of Demeter (The principle
of least knowledge):&lt;/a&gt; Only talk to your immediate friends.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://en.wikipedia.org/wiki/Delegation"&gt;Delegation&lt;/a&gt;&lt;/strong&gt; is
when you hand over the responsibility for a particular task to another class or method.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://en.wikipedia.org/wiki/Object_composition"&gt;Composition&lt;/a&gt;&lt;/strong&gt; allows
you to use behavior from a family of other classes, and to change that behavior at
runtime.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://en.wikipedia.org/wiki/Object_composition#Aggregation"&gt;Aggregation&lt;/a&gt;&lt;/strong&gt; is
when one class is used as part of another class, but still exists outside of that
other class.
&lt;/p&gt;
&lt;p&gt;
Encapsulate what varies.
&lt;/p&gt;
&lt;p&gt;
Favor composition over inheritance.
&lt;/p&gt;
&lt;p&gt;
Program to interfaces, not implementations.
&lt;/p&gt;
&lt;p&gt;
Strive for loosely coupled designs between objects that interact.
&lt;/p&gt;
&lt;p&gt;
Depend on abstractions. Do not depend on concrete classes.
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/1115DCWP81L.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Head First Object-Oriented Analysis and Design: A Brain Friendly Guide to OOA&amp;amp;D
(Head First)&lt;/b&gt;
&lt;br&gt;
by Brett D. McLaughlin, Gary Pollice, Dave West&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596008678%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596008678%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=e5580370-31a1-411c-8a28-6c727ec7c193" /&gt;</description>
      <category>Books</category>
      <category>Design Patterns</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=1993eedc-3cfd-40af-b589-5f40b050239c</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,1993eedc-3cfd-40af-b589-5f40b050239c.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
On my ride home from work Friday evening I finished reading...
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://g-ec2.images-amazon.com/images/I/01M9T7729AL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>The Greatness Guide: Powerful Secrets for Getting to World Class</b>
                  <br />
by Robin Sharma<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0061229881%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0061229881%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
This was an excellent read! I just couldn't put it down after I first cracked it open.
My boss at work popped by my desk on Wednesday, and handed me the book. She said that
I would probably enjoy it! I did! Thanks Leanne!
</p>
        <p>
The chapters are short and sweet, which makes it so easy to just pick up and read
a chapter here and there. I wanted to share some of the insights from this book, but
I highly encourage you to go out and read it yourself.
</p>
        <blockquote>
          <p>
When I was growing up my father once told me: "Cut back on your rent or cut back on
what you spend on food but never worry about investing money in a good book."
</p>
        </blockquote>
        <p>
I really enjoy reading books. It really is like having a conversation with all sorts
of great minds and views of the world! I'm really looking forward to one day
being able to look back and think about all the wonderful books I've studied. I've
learned so much from such a simple act, and teaching someone to read truly is precious.
</p>
        <blockquote>
          <p>
"Not one of the uber-successful people I've worked with as a leadership coach got
there without outworking everyone around them."
</p>
        </blockquote>
        <p>
One of the other things that Robin mentioned in his book was that the price of discipline
is not as painful as the price of regret. It's absolutely important to work heard
to get ahead and for a sense of accomplishment. Feeling good about where you are,
because of how hard you've worked is great!
</p>
        <blockquote>
          <p>
"Faced an uphill battle: an aggressive enemy, brutal disease and scarce resources.
As they marched inland to do battle, Cortes ordered one of his lieutenants back to
the beach with a single instruction: "Burn our boats.""
</p>
        </blockquote>
        <p>
Don't allow failure to be an option. Sometimes when dealing with all to difficult
situations it's to easy to look for the backdoor out. But by changing your thinking
so that you don't allow failure to be an option, you allow yourself to succeed. I
also think this applied to being faithful and loyal to those you care about. It seems
these days, it's so normal for partners to cheat on one another. Think ahead and don't
allow yourself to be caught up in the moment.
</p>
        <blockquote>
          <p>
"You need to practice to get to your greatness. Athletes know this so very well. Why
does it seem so foreign to the rest of us?"
</p>
        </blockquote>
        <p>
Duh! So schedule time to practice! In Jr. High and High School I had a friend who
was a super athlete, he had accomplished more before 7 am then the regular teenager,
including myself. He got it!
</p>
        <blockquote>
          <p>
"If you eat three times a day you'll be fed. But if you read three times a day you'll
be wise." - Shimon Peres
</p>
        </blockquote>
        <p>
For some reason this quote spoke to me. It was silly how straight forward and simple
this thought is, but it makes darn good sense!
</p>
        <blockquote>
          <p>
"Study hip hop artists... You'll learn all you need to learn about taking a brand
to the top of the mountain."
</p>
        </blockquote>
        <p>
I'm a fan of hip hop, so any plug for it makes me smile!
</p>
        <p>
I've downloaded every episode of Robin's podcast and found time each morning to listen
to one episode each morning. I found that it's been a great way to start my day. I
just hope he continues to publish more episodes.
</p>
        <p>
This Wednesday, September, 12, 2007 I will be attending a private presentation
by Robin Sharma here in Calgary. I'm really looking forward to the presentation!
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=1993eedc-3cfd-40af-b589-5f40b050239c" />
      </body>
      <title>Bringer Of Light</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,1993eedc-3cfd-40af-b589-5f40b050239c.aspx</guid>
      <link>http://mokhan.ca/blog/2007/09/09/Bringer+Of+Light.aspx</link>
      <pubDate>Sun, 09 Sep 2007 22:47:03 GMT</pubDate>
      <description>&lt;p&gt;
On my ride home from work Friday evening I finished reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://g-ec2.images-amazon.com/images/I/01M9T7729AL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;The Greatness Guide: Powerful Secrets for Getting to World Class&lt;/b&gt;
&lt;br&gt;
by Robin Sharma&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0061229881%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0061229881%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
This was an excellent read! I just couldn't put it down after I first cracked it open.
My boss at work popped by my desk on Wednesday, and handed me the book. She said that
I would probably enjoy it! I did! Thanks Leanne!
&lt;/p&gt;
&lt;p&gt;
The chapters are short and sweet, which makes it so easy to just pick up and read
a chapter here and there. I wanted to share some of the insights from this book, but
I highly encourage you to go out and read it yourself.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
When I was growing up my father once told me: "Cut back on your rent or cut back on
what you spend on food but never worry about investing money in a good book."
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I really enjoy reading books. It really is like having a conversation with all&amp;nbsp;sorts
of&amp;nbsp;great minds and views of the world! I'm really looking forward to one day
being able to look back and think about all the wonderful books I've studied. I've
learned so much from such a simple act, and teaching someone to read truly is precious.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"Not one of the uber-successful people I've worked with as a leadership coach got
there without outworking everyone around them."
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
One of the other things that Robin mentioned in his book was that the price of discipline
is not as painful as the price of regret. It's absolutely important to work heard
to get ahead and for a sense of accomplishment. Feeling good about where you are,
because of how hard you've worked is great!
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"Faced an uphill battle: an aggressive enemy, brutal disease and scarce resources.
As they marched inland to do battle, Cortes ordered one of his lieutenants back to
the beach with a single instruction: "Burn our boats.""
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Don't allow failure to be an option. Sometimes when dealing with all to difficult
situations it's to easy to look for the backdoor out. But by changing your thinking
so that you don't allow failure to be an option, you allow yourself to succeed. I
also think this applied to being faithful and loyal to those you care about. It seems
these days, it's so normal for partners to cheat on one another. Think ahead and don't
allow yourself to be caught up in the moment.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"You need to practice to get to your greatness. Athletes know this so very well. Why
does it seem so foreign to the rest of us?"
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Duh! So schedule time to practice! In Jr. High and High School I had a friend who
was a super athlete, he had accomplished more before 7 am&amp;nbsp;then the regular teenager,
including myself. He got it!
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"If you eat three times a day you'll be fed. But if you read three times a day you'll
be wise." - Shimon Peres
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
For some reason this quote spoke to me. It was silly how straight forward and simple
this thought is, but it makes darn good sense!
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"Study hip hop artists... You'll learn all you need to learn about taking a brand
to the top of the mountain."
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I'm a fan of hip hop, so any plug for it makes me smile!
&lt;/p&gt;
&lt;p&gt;
I've downloaded every episode of Robin's podcast and found time each morning to listen
to one episode each morning. I found that it's been a great way to start my day. I
just hope he continues to publish more episodes.
&lt;/p&gt;
&lt;p&gt;
This Wednesday, September, 12, 2007&amp;nbsp;I will be attending a private presentation
by Robin Sharma here in Calgary. I'm really looking forward to the presentation!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=1993eedc-3cfd-40af-b589-5f40b050239c" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=1bd3191a-5075-4e60-88c5-449eefbedfe3</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,1bd3191a-5075-4e60-88c5-449eefbedfe3.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
To demo how the Factory Method and Abstract Factory patterns work I've put together
an <a href="http://mokhan.ca/blog/content/binary/DesignPatterns.Factory.zip">example
in C#</a>. For this example I've got 2 different Banks, CIBC, and Royal Bank. Each
bank offers a chequing and savings account. Through the use of the Factory Method
and Abstract Factory, the sample shows you how to create different types of bank accounts.
</p>
        <blockquote>
          <p>
"The Factory Method Pattern defines an interface for creating an object, but lets
subclasses decide which class to instantiate. Factory Method lets a class defer instantiation
to subclasses." - Head First Design Patterns
</p>
        </blockquote>
        <p>
IBank has a single method called "GetAccountFactory()" that returns a IBankAccountFactory.
This allows types that implement the interface to specify what type of bank account
factory to construct and return.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">interface</span>
          <span style="color: rgb(43,145,175)">IBank</span> { <span style="color: rgb(0,0,255)">string</span> Name
{ <span style="color: rgb(0,0,255)">get</span>; } <span style="color: rgb(43,145,175)">IBankAccountFactory</span> GetAccountFactory(
); }</pre>
        <p>
So CIBC implementation of IBank will return a CIBCBankAccountFactory.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">CibcBank</span> : <span style="color: rgb(43,145,175)">Bank</span>, <span style="color: rgb(43,145,175)">IBank</span> { <span style="color: rgb(0,0,255)">public</span> CibcBank(
) : <span style="color: rgb(0,0,255)">base</span>( <span style="color: rgb(163,21,21)">"CIBC"</span> )
{} <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">override</span><span style="color: rgb(43,145,175)">IBankAccountFactory</span> GetAccountFactory(
) { <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">CibcBankAccountFactory</span>(
); } }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <a href="http://11011.net/software/vspaste">
        </a>
        <blockquote>
          <p>
"The Abstract Factory Pattern provides an interface for creating families of related
or dependent objects without specifying their concrete classes." - Head First Design
Patterns
</p>
        </blockquote>
        <p>
IBankAccountFactory is an abstract factory for creating different types of bank accounts.
In my provided example you'll see that the IBankAccountFactory has two methods defined
in it, both of which return an IBankAccount:
</p>
        <ul>
          <li>
CreateChequingAccount() 
</li>
          <li>
CreateSavingsAccount()</li>
        </ul>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">interface</span>
          <span style="color: rgb(43,145,175)">IBankAccountFactory</span> { <span style="color: rgb(43,145,175)">IBankAccount</span> CreateChequingAccount(
); <span style="color: rgb(43,145,175)">IBankAccount</span> CreateSavingsAccount(
); }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
To create a CIBC chequing account, the client code might look something like this:
</p>
        <pre class="code">
          <span style="color: rgb(43,145,175)">IBank</span> bank
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">CibcBank</span>(
); <span style="color: rgb(43,145,175)">IBankAccountFactory</span> factory = bank.GetAccountFactory(
); <span style="color: rgb(43,145,175)">IBankAccount</span> chequingAccount = factory.CreateChequingAccount(
);</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
 
</p>
        <p>
To create a Royal Bank chequing account, the client code might look something like
this:
</p>
        <pre class="code">
          <span style="color: rgb(43,145,175)">IBank</span> bank
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">RoyalBank</span>(
); <span style="color: rgb(43,145,175)">IBankAccountFactory</span> factory = bank.GetAccountFactory(
); <span style="color: rgb(43,145,175)">IBankAccount</span> chequingAccount = factory.CreateChequingAccount(
);</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
 
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/115M5YwkVnL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Head First Design Patterns (Head First)</b>
                  <br />
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596007124%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596007124%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <a href="http://mokhan.ca/blog/content/binary/DesignPatterns.Factory.zip">DesignPatterns.Factory.zip
(9.16 KB)</a>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=1bd3191a-5075-4e60-88c5-449eefbedfe3" />
      </body>
      <title>The Factory Pattern</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,1bd3191a-5075-4e60-88c5-449eefbedfe3.aspx</guid>
      <link>http://mokhan.ca/blog/2007/09/03/The+Factory+Pattern.aspx</link>
      <pubDate>Mon, 03 Sep 2007 21:42:39 GMT</pubDate>
      <description>&lt;p&gt;
To demo how the Factory Method and Abstract Factory patterns work I've put together
an &lt;a href="http://mokhan.ca/blog/content/binary/DesignPatterns.Factory.zip"&gt;example
in C#&lt;/a&gt;. For this example I've got 2 different Banks, CIBC, and Royal Bank. Each
bank offers a chequing and savings account. Through the use of the Factory Method
and Abstract Factory, the sample shows you how to create different types of bank accounts.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"The Factory Method Pattern defines an interface for creating an object, but lets
subclasses decide which class to instantiate. Factory Method lets a class defer instantiation
to subclasses." - Head First Design Patterns
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
IBank has a single method called "GetAccountFactory()" that returns a IBankAccountFactory.
This allows types that implement the interface to specify what type of bank account
factory to construct and return.
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IBank&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; Name
{ &lt;span style="color: rgb(0,0,255)"&gt;get&lt;/span&gt;; } &lt;span style="color: rgb(43,145,175)"&gt;IBankAccountFactory&lt;/span&gt; GetAccountFactory(
); }&lt;/pre&gt;
&lt;p&gt;
So CIBC implementation of IBank will return a CIBCBankAccountFactory.
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;CibcBank&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;Bank&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;IBank&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; CibcBank(
) : &lt;span style="color: rgb(0,0,255)"&gt;base&lt;/span&gt;( &lt;span style="color: rgb(163,21,21)"&gt;"CIBC"&lt;/span&gt; )
{} &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;override&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IBankAccountFactory&lt;/span&gt; GetAccountFactory(
) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;CibcBankAccountFactory&lt;/span&gt;(
); } }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; &lt;blockquote&gt; 
&lt;p&gt;
"The Abstract Factory Pattern provides an interface for creating families of related
or dependent objects without specifying their concrete classes." - Head First Design
Patterns
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
IBankAccountFactory is an abstract factory for creating different types of bank accounts.
In my provided example you'll see that the IBankAccountFactory has two methods defined
in it, both of which return an&amp;nbsp;IBankAccount:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
CreateChequingAccount() 
&lt;li&gt;
CreateSavingsAccount()&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IBankAccountFactory&lt;/span&gt; { &lt;span style="color: rgb(43,145,175)"&gt;IBankAccount&lt;/span&gt; CreateChequingAccount(
); &lt;span style="color: rgb(43,145,175)"&gt;IBankAccount&lt;/span&gt; CreateSavingsAccount(
); }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
To create a CIBC chequing account, the client code might look something like this:
&lt;/p&gt;
&lt;pre class="code"&gt;            &lt;span style="color: rgb(43,145,175)"&gt;IBank&lt;/span&gt; bank
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;CibcBank&lt;/span&gt;(
); &lt;span style="color: rgb(43,145,175)"&gt;IBankAccountFactory&lt;/span&gt; factory = bank.GetAccountFactory(
); &lt;span style="color: rgb(43,145,175)"&gt;IBankAccount&lt;/span&gt; chequingAccount = factory.CreateChequingAccount(
);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
To create a Royal Bank chequing account, the client code might look something like
this:
&lt;/p&gt;
&lt;pre class="code"&gt;            &lt;span style="color: rgb(43,145,175)"&gt;IBank&lt;/span&gt; bank
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;RoyalBank&lt;/span&gt;(
); &lt;span style="color: rgb(43,145,175)"&gt;IBankAccountFactory&lt;/span&gt; factory = bank.GetAccountFactory(
); &lt;span style="color: rgb(43,145,175)"&gt;IBankAccount&lt;/span&gt; chequingAccount = factory.CreateChequingAccount(
);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/115M5YwkVnL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Head First Design Patterns (Head First)&lt;/b&gt;
&lt;br&gt;
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596007124%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596007124%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;a href="http://mokhan.ca/blog/content/binary/DesignPatterns.Factory.zip"&gt;DesignPatterns.Factory.zip
(9.16 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=1bd3191a-5075-4e60-88c5-449eefbedfe3" /&gt;</description>
      <category>Books</category>
      <category>Design Patterns</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=8d1b9b64-a003-4e5f-8f3e-14d7ab29971f</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,8d1b9b64-a003-4e5f-8f3e-14d7ab29971f.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/11FNgijPZ8L.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>User Stories Applied: For Agile Software Development (The Addison-Wesley Signature
Series)</b>
                  <br />
by Mike Cohn<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321205685%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321205685%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <h2>The XP Values
</h2>
        <ul>
          <li>
            <strong>Communication</strong>: Most desirable is face to face communication where
we can talk, respond, gesture and draw on a whiteboard. Talking = good, documents
= bad! 
</li>
          <li>
            <strong>Simplicity</strong>: Focus on creating a solution to the problem faced today,
not the problem anticipated tomorrow. 
</li>
          <li>
            <strong>Feedback</strong>: Developers give and get feedback from pair programming,
from automated tests, continuous integration. Customers are part of the team even
sitting in the same space with the developers, and provide feedback through constant
interaction with the team, and through acceptance tests.  
</li>
          <li>
            <strong>Courage</strong>: They have courage to refactor their code, proceed with an
overall master architecture.</li>
        </ul>
        <h2>The Principles of XP
</h2>
        <ul>
          <li>
            <strong>Rapid Feedback</strong>: Constantly sending and receiving feedback, and responding
to it. 
</li>
          <li>
            <strong>Assuming Simplicity</strong>: Favor simplicity and attempt to create a simple
solution before evolving to a complex one. 
</li>
          <li>
            <strong>Incremental Change</strong>: Improve the software through small, incremental
changes. 
</li>
          <li>
            <strong>Embracing Change</strong>: Developers are able to adapt and accommodate change. 
</li>
          <li>
            <strong>Doing Quality Work</strong>: Insist that the software consistently exhibits
the highest level of quality workmanship.</li>
        </ul>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=8d1b9b64-a003-4e5f-8f3e-14d7ab29971f" />
      </body>
      <title>The Principles and Values of XP</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,8d1b9b64-a003-4e5f-8f3e-14d7ab29971f.aspx</guid>
      <link>http://mokhan.ca/blog/2007/08/31/The+Principles+And+Values+Of+XP.aspx</link>
      <pubDate>Fri, 31 Aug 2007 12:40:47 GMT</pubDate>
      <description>&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/11FNgijPZ8L.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;User Stories Applied: For Agile Software Development (The Addison-Wesley Signature
Series)&lt;/b&gt;
&lt;br&gt;
by Mike Cohn&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321205685%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321205685%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;h2&gt;The XP Values
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Communication&lt;/strong&gt;: Most desirable is face to face communication where
we can talk, respond, gesture and draw on a whiteboard. Talking = good, documents
= bad! 
&lt;li&gt;
&lt;strong&gt;Simplicity&lt;/strong&gt;: Focus on creating a solution to the problem faced today,
not the problem anticipated tomorrow. 
&lt;li&gt;
&lt;strong&gt;Feedback&lt;/strong&gt;:&amp;nbsp;Developers give and get feedback from pair programming,
from automated tests, continuous integration. Customers are part of the team even
sitting in the same space with the developers, and provide feedback through constant
interaction with the team, and through acceptance tests.&amp;nbsp; 
&lt;li&gt;
&lt;strong&gt;Courage&lt;/strong&gt;: They have courage to refactor their code, proceed with an
overall master architecture.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The Principles of XP
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Rapid Feedback&lt;/strong&gt;: Constantly sending and receiving feedback, and responding
to it. 
&lt;li&gt;
&lt;strong&gt;Assuming Simplicity&lt;/strong&gt;: Favor simplicity and attempt to create a simple
solution before evolving to a complex one. 
&lt;li&gt;
&lt;strong&gt;Incremental Change&lt;/strong&gt;: Improve the software through small, incremental
changes. 
&lt;li&gt;
&lt;strong&gt;Embracing Change&lt;/strong&gt;: Developers are able to adapt and accommodate change. 
&lt;li&gt;
&lt;strong&gt;Doing Quality Work&lt;/strong&gt;: Insist that the software consistently exhibits
the highest level of quality workmanship.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=8d1b9b64-a003-4e5f-8f3e-14d7ab29971f" /&gt;</description>
      <category>Agile</category>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=7578e998-91fb-4698-a298-d3314f4f4a00</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,7578e998-91fb-4698-a298-d3314f4f4a00.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm still fascinated by the Agile XP methodology. So when I came across the overview
of XP in the Appendix of...
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/11FNgijPZ8L.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>User Stories Applied: For Agile Software Development (The Addison-Wesley Signature
Series)</b>
                  <br />
by Mike Cohn<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321205685%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321205685%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
 
</p>
        <p>
I had to read on. Here's what I learned:
</p>
        <h2>Roles
</h2>
        <ul>
          <li>
The XP customer role is responsible for writing stories, prioritizing stories, and
writing and executing tests that demonstrate that stories were developed as expected. 
</li>
          <li>
The XP programmer role encompasses a broad range of technical skills. XP projects
tend not to draw distinctions between programmers, designers, DBA's and so on. 
</li>
          <li>
XP teams benefit for the use of an XP coach and possibly a project manager. The coach
is responsible for monitoring the team's use of the XP practices and gently nudging
them back on track when they stray.</li>
        </ul>
        <h2>The 12 Practices
</h2>
        <h3>Small Releases
</h3>
        <p>
Project progress in a series of iterations, which are typically 1 to 3 weeks long.
Features are fully delivered within a single iteration.
</p>
        <h3>The Planning Game
</h3>
        <ul>
          <li>
This is the name for release and iteration planning where developers and customers
collaborate to make predictions about the future. 
</li>
          <li>
Prior to planning, the customer has written user stories on note cards and developers
have estimated the cost of magnitude of each story and have written the estimate on
the story card.</li>
        </ul>
        <h3>Refactoring
</h3>
        <ul>
          <li>
Refers to the restructuring or rewriting of code so as to improve the code without
changing its external behavior. 
</li>
          <li>
XP advocates constant attention to refactoring. Whenever a programmer makes a change
to code that should be refactored, she is required to refactor it. 
</li>
          <li>
She's not <strong>encouraged</strong> to refactor it; she's <strong>required</strong> to
refactor it. 
</li>
          <li>
Instead of spending time upfront thinking through a system in advance of coding it,
and therefore taking guesses at some aspects of its behavior, XP systems are refactored
and kept in a state that perfectly meets known, implemented requirements.</li>
        </ul>
        <h3>Testing
</h3>
        <ul>
          <li>
The developers write automated unit tests. 
</li>
          <li>
The customers write acceptance tests. 
</li>
          <li>
In test-driven development, tests are written before the code. Developers follow a
short cycle of test-code-test-code... No operational code may be written except in
response to a failing test.</li>
        </ul>
        <h3>Pair Programming
</h3>
        <ul>
          <li>
Refers to 2 programmers sharing one computer and 2 brains to write code. One programmer
types the code, the second is watching the code develop and thinking more broadly
about the code. 
</li>
          <li>
This leads to lower defect counts, less code is written to solve the same problem,
problems being solved more quickly, more people understand each piece of code, an
increase in developer satisfaction. 
</li>
          <li>
It requires discipline to refactor every time you notice poorly structured code.</li>
        </ul>
        <h3>Sustainable Pace
</h3>
        <ul>
          <li>
The believe is that an XP team moving at a consistent but brisk pace will achieve
more over a period of time than will a team working at a pace they cannot sustain
over a long period of time. 
</li>
          <li>
It is up to the team to determine their sustained pace. 
</li>
          <li>
A team will typically devote around 6 hours per day to pairing and spend the remainder
of the day in other activities. 
</li>
          <li>
An XP coach is responsible for monitoring the team for burnout.</li>
        </ul>
        <h3>Team Code Ownership
</h3>
        <ul>
          <li>
It's common in non-XP teams for individuals to "own" portions of a systems code. This
leads to comments like "We can't change the billing source code until Eli gets back
from vacation." 
</li>
          <li>
All code is owned by everyone. 
</li>
          <li>
Pairs are expected to change code they didn't write. 
</li>
          <li>
A strong suite of unit tests ensures that changes do not introduce unanticipated side
effects.</li>
        </ul>
        <h3>Coding Standard
</h3>
        <ul>
          <li>
XP teams collectively own their source code, so it's important to follow a coding
standard. 
</li>
          <li>
A small, close-knit team may be able to get by without a written, formalized coding
standard.</li>
        </ul>
        <h3>Simple Design
</h3>
        <ul>
          <li>
Pursue a goal of having the simplest possible design that delivers the features a
customer needs. 
</li>
          <li>
The operational code and the test code fully convey the programmers intent. 
</li>
          <li>
There is no duplicate code. 
</li>
          <li>
The system uses the least number of classes. 
</li>
          <li>
The system uses the least number of methods.</li>
        </ul>
        <h3>Metaphor
</h3>
        <ul>
          <li>
Quest for simple design by finding a metaphor that can be used for the whole system.
The metaphor describes how they think about the system. 
</li>
          <li>
E.g. "The system is like a chalkboard and various parts of the system can write on
the chalkboard. When a user is done with the system she can either save the contents
of the chalkboard or erase them."</li>
        </ul>
        <h3>Continuous Integration
</h3>
        <ul>
          <li>
Code is integrated continuously. 
</li>
          <li>
A developer completes a small change, he checks the change into source control, where
the CI box initiates a full build. When the build is finished a full set of unit tests
are run. If any tests fail, the developer is notified by email and told about the
failure. 
</li>
          <li>
Integration problems are fixed one at a time in extremely small batches as soon as
they occur.</li>
        </ul>
        <h3>On-Site Customer
</h3>
        <ul>
          <li>
 The customer is expected to sit with and be part of the development team. The
customer writes the stories and the acceptance tests and is also available to answer
questions as they arise. 
</li>
          <li>
If the customer is not on site, delays will disrupt the predictable progress of the
XP team.</li>
        </ul>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=7578e998-91fb-4698-a298-d3314f4f4a00" />
      </body>
      <title>Learning To Become More XP</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,7578e998-91fb-4698-a298-d3314f4f4a00.aspx</guid>
      <link>http://mokhan.ca/blog/2007/08/30/Learning+To+Become+More+XP.aspx</link>
      <pubDate>Thu, 30 Aug 2007 13:04:17 GMT</pubDate>
      <description>&lt;p&gt;
I'm still fascinated by the Agile XP methodology. So when I came across the overview
of XP in the Appendix of...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/11FNgijPZ8L.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;User Stories Applied: For Agile Software Development (The Addison-Wesley Signature
Series)&lt;/b&gt;
&lt;br&gt;
by Mike Cohn&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321205685%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321205685%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
I had to read on. Here's what I learned:
&lt;/p&gt;
&lt;h2&gt;Roles
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
The XP customer role is responsible for writing stories, prioritizing stories, and
writing and executing tests that demonstrate that stories were developed as expected. 
&lt;li&gt;
The XP programmer role encompasses a broad range of technical skills. XP projects
tend not to draw distinctions between programmers, designers, DBA's and so on. 
&lt;li&gt;
XP teams benefit for the use of an XP coach and possibly a project manager. The coach
is responsible for monitoring the team's use of the XP practices and gently nudging
them back on track when they stray.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The 12 Practices
&lt;/h2&gt;
&lt;h3&gt;Small Releases
&lt;/h3&gt;
&lt;p&gt;
Project progress in a series of iterations, which are typically 1 to 3 weeks long.
Features are fully delivered within a single iteration.
&lt;/p&gt;
&lt;h3&gt;The Planning Game
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
This is the name for release and iteration planning where developers and customers
collaborate to make predictions about the future. 
&lt;li&gt;
Prior to planning, the customer has written user stories on note cards and developers
have estimated the cost of magnitude of each story and have written the estimate on
the story card.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Refactoring
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
Refers to the restructuring or rewriting of code so as to improve the code without
changing its external behavior. 
&lt;li&gt;
XP advocates constant attention to refactoring. Whenever a programmer makes a change
to code that should be refactored, she is required to refactor it. 
&lt;li&gt;
She's not &lt;strong&gt;encouraged&lt;/strong&gt; to refactor it; she's &lt;strong&gt;required&lt;/strong&gt; to
refactor it. 
&lt;li&gt;
Instead of spending time upfront thinking through a system in advance of coding it,
and therefore taking guesses at some aspects of its behavior, XP systems are refactored
and kept in a state that perfectly meets known, implemented requirements.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Testing
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
The developers write automated unit tests. 
&lt;li&gt;
The customers write acceptance tests. 
&lt;li&gt;
In test-driven development, tests are written before the code. Developers follow a
short cycle of test-code-test-code... No operational code may be written except in
response to a failing test.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Pair Programming
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
Refers to 2 programmers sharing one computer and 2 brains to write code. One programmer
types the code, the second is watching the code develop and thinking more broadly
about the code. 
&lt;li&gt;
This leads to lower defect counts, less code is written to solve the same problem,
problems being solved more quickly, more people understand each piece of code, an
increase in developer satisfaction. 
&lt;li&gt;
It requires discipline&amp;nbsp;to refactor every time you notice poorly structured code.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Sustainable Pace
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
The believe is that an XP team moving at a consistent but brisk pace will achieve
more over a period of time than will a team working at a pace they cannot sustain
over a long period of time. 
&lt;li&gt;
It is up to the team to determine their sustained pace. 
&lt;li&gt;
A team will typically devote around 6 hours per day to pairing and spend the remainder
of the day in other activities. 
&lt;li&gt;
An XP coach is responsible for monitoring the team for burnout.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Team Code Ownership
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
It's common in non-XP teams for individuals to "own" portions of a systems code. This
leads to comments like "We can't change the billing source code until Eli gets back
from vacation." 
&lt;li&gt;
All code is owned by everyone. 
&lt;li&gt;
Pairs are expected to change code they didn't write. 
&lt;li&gt;
A strong suite of unit tests ensures that changes do not introduce unanticipated side
effects.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Coding Standard
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
XP teams collectively own their source code, so it's important to follow a coding
standard. 
&lt;li&gt;
A small, close-knit team may be able to get by without a written, formalized coding
standard.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Simple Design
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
Pursue a goal of having the simplest possible design that delivers the features a
customer needs. 
&lt;li&gt;
The operational code and the test code fully convey the programmers intent. 
&lt;li&gt;
There is no duplicate code. 
&lt;li&gt;
The system uses the least number of classes. 
&lt;li&gt;
The system uses the least number of methods.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Metaphor
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
Quest for simple design by finding a metaphor that can be used for the whole system.
The metaphor describes how they think about the system. 
&lt;li&gt;
E.g. "The system is like a chalkboard and various parts of the system can write on
the chalkboard. When a user is done with the system she can either save the contents
of the chalkboard or erase them."&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Continuous Integration
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
Code is integrated continuously. 
&lt;li&gt;
A developer completes a small change, he checks the change into source control, where
the CI box initiates a full build. When the build is finished a full set of unit tests
are run. If any tests fail, the developer is notified by email and told about the
failure. 
&lt;li&gt;
Integration problems are fixed one at a time in extremely small batches as soon as
they occur.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;On-Site Customer
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&amp;nbsp;The customer is expected to sit with and be part of the development team. The
customer writes the stories and the acceptance tests and is also available to answer
questions as they arise. 
&lt;li&gt;
If the customer is not on site, delays will disrupt the predictable progress of the
XP team.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=7578e998-91fb-4698-a298-d3314f4f4a00" /&gt;</description>
      <category>Agile</category>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=94da6a3c-9775-4719-b6d0-0307a1c7f812</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,94da6a3c-9775-4719-b6d0-0307a1c7f812.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last night I finished reading...
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/11FNgijPZ8L.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>User Stories Applied: For Agile Software Development (The Addison-Wesley Signature
Series)</b>
                  <br />
by Mike Cohn<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321205685%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321205685%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
It was a nice quick and dirty read, to get my feet wet in the world of applying user
stories. I really prefer working with user stories as opposed to full blown system
requirements specifications. Although, a typical SRS is much thicker then a set of
user stories, I think more information is delivered through user stories because it
done so piece by piece. As you require the information, it's your responsibility to
gather it.
</p>
        <p>
I want to share some of my favorite quotes from the book.
</p>
        <blockquote>
          <p>
"Pay attention to who is contributing during a story writing workshop. Occasionally
a participant will remain silent through much or all of the meeting. If this is the
case, talk to the participant during one of the breaks and make sure she's comfortable
with the process. Some participants are reluctant to speak up in front of their peers
or supervisors, which is why it is important that story ideas not be judged during
these sessions. Once participants become comfortable that their ideas will simply
be noted, not debated, at this point they will contribute more readily."
</p>
        </blockquote>
        <p>
I have to admit that at my first story writing workshop I didn't say much. It was
kind of a foreign concept to me and I worried about getting shot down by the other
developers if I mentioned a story idea. I felt like there was a good chance that would
occur because the rest of the team felt they had a similar vision of how the product
would look and feel before and discussion had even begun. I later realized that
they did indeed want to hear my story ideas, but it just took some time getting used
to the culture of the team.
</p>
        <blockquote>
          <p>
"When you cannot find, or get access to, a real user, avoid falling into the trap
of thinking you know your users' minds and do not need or can ignore your user proxy.
While each type of user proxy has some type of shortcoming that makes her less desirable
than a real user, most developers come with even more shortcomings for pretending
to be a real user. In general, developers do not have marketing backgrounds that allow
them to understand the relative value of features, they do not have the same amount
of customer contact as salespeople, they are not domain experts, and so on."
</p>
        </blockquote>
        <p>
I know as a developer that there are many times where I know how I would like a piece
of software to work. Because it would work well for me, but ultimately that's not
always going to work best for the end user. It's difficult to put yourselves in someone
else's shoe to try to think like they would. It's much easier to just ask, instead
of making a design decision, implementing it then later having them tell you that's
not what they wanted.
</p>
        <blockquote>
          <p>
"Ideally the customer writes the stories. On many projects the developers help out,
either by doing the actual writing during an initial story writing workshop or by
suggesting new stories to the customer. But, responsibility for writing stories resides
with the customer and cannot be passed to the developers."
</p>
        </blockquote>
        <p>
Wow... I had no idea. Right now we're writing the user stories...
</p>
        <blockquote>
          <p>
"In a blame-filled organization there are always some individuals who have learned
that their best decision is to avoid all responsibility. If you're not responsible
for something you can't be blamed for it when it fails, yet there's usually a way
to lay claim to at least some of the success. Individuals in this type of culture
will want nothing to do with hard decisions like prioritizing features into and out
of releases. They'll fall back on statements such as "It's not my problem that you
can't complete everything by the deadline, figure out a way to do it."
</p>
        </blockquote>
        <p>
This seems to happen more often then not. I think when someone because slightly hostile,
it's usually because of their own insecurities. But reading the above statement just
helped me to realize to think about what they're going through. Who's grilling them,
and how can I help so that they're are happy with the software but it also makes them
look good to their peers.
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=94da6a3c-9775-4719-b6d0-0307a1c7f812" />
      </body>
      <title>It's Story Time</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,94da6a3c-9775-4719-b6d0-0307a1c7f812.aspx</guid>
      <link>http://mokhan.ca/blog/2007/08/29/Its+Story+Time.aspx</link>
      <pubDate>Wed, 29 Aug 2007 12:35:02 GMT</pubDate>
      <description>&lt;p&gt;
Last night I finished reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/11FNgijPZ8L.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;User Stories Applied: For Agile Software Development (The Addison-Wesley Signature
Series)&lt;/b&gt;
&lt;br&gt;
by Mike Cohn&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321205685%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321205685%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
It was a nice quick and dirty read, to get my feet wet in the world of applying user
stories. I really prefer working with user stories as opposed to full blown system
requirements specifications. Although, a typical SRS is much thicker then a set of
user stories, I think more information is delivered through user stories because it
done so piece by piece. As you require the information, it's your responsibility to
gather it.
&lt;/p&gt;
&lt;p&gt;
I want to share some of my favorite quotes from the book.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"Pay attention to who is contributing during a story writing workshop. Occasionally
a participant will remain silent through much or all of the meeting. If this is the
case, talk to the participant during one of the breaks and make sure she's comfortable
with the process. Some participants are reluctant to speak up in front of their peers
or supervisors, which is why it is important that story ideas not be judged during
these sessions. Once participants become comfortable that their ideas will simply
be noted, not debated, at this point they will contribute more readily."
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I have to admit that at my first story writing workshop I didn't say much. It was
kind of a foreign concept to me and I worried about getting shot down by the other
developers if I mentioned a story idea. I felt like there was a good chance that would
occur because the rest of the team felt they had a similar vision of how the product
would look and feel before and discussion had even begun. I later&amp;nbsp;realized that
they did indeed want to hear my story ideas, but it just took some time getting used
to the culture of the team.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"When you cannot find, or get access to, a real user, avoid falling into the trap
of thinking you know your users' minds and do not need or can ignore your user proxy.
While each type of user proxy has some type of shortcoming that makes her less desirable
than a real user, most developers come with even more shortcomings for pretending
to be a real user. In general, developers do not have marketing backgrounds that allow
them to understand the relative value of features, they do not have the same amount
of customer contact as salespeople, they are not domain experts, and so on."
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I know as a developer that there are many times where I know how I would like a piece
of software to work. Because it would work well for me, but ultimately that's not
always going to work best for the end user. It's difficult to put yourselves in someone
else's shoe to try to think like they would. It's much easier to just ask, instead
of making a design decision, implementing it then later having them tell you that's
not what they wanted.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"Ideally the customer writes the stories. On many projects the developers help out,
either by doing the actual writing during an initial story writing workshop or by
suggesting new stories to the customer. But, responsibility for writing stories resides
with the customer and cannot be passed to the developers."
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Wow... I had no idea. Right now we're writing the user stories...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"In a blame-filled organization there are always some individuals who have learned
that their best decision is to avoid all responsibility. If you're not responsible
for something you can't be blamed for it when it fails, yet there's usually a way
to lay claim to at least some of the success. Individuals in this type of culture
will want nothing to do with hard decisions like prioritizing features into and out
of releases. They'll fall back on statements such as "It's not my problem that you
can't complete everything by the deadline, figure out a way to do it."
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
This seems to happen more often then not. I think when someone because slightly hostile,
it's usually because of their own insecurities. But reading the above statement just
helped me to realize to think about what they're going through. Who's grilling them,
and how can I help so that they're are happy with the software but it also makes them
look good to their peers.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=94da6a3c-9775-4719-b6d0-0307a1c7f812" /&gt;</description>
      <category>Agile</category>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=603e6157-8879-4bfe-9135-46f875452fcf</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,603e6157-8879-4bfe-9135-46f875452fcf.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <blockquote>
          <p>
"The State Pattern allows an object to alter its behavior when its internal state
changes. The object will appear to change it's class." - Head First Design Pattern
</p>
        </blockquote>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/115M5YwkVnL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Head First Design Patterns (Head First)</b>
                  <br />
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596007124%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596007124%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
 
</p>
        <p>
Let's say I've got a point of sale terminal used for processing financial transactions.
Let's say that at any given time the terminal can be in 1 of 6 states. Those states
are:
</p>
        <ul>
          <li>
            <strong>Idle State:</strong> During this state an idle message is displayed on the
screen of the POS terminal. 
</li>
          <li>
            <strong>Card Swiped State:</strong> The terminal enters this state when a card is
swiped. 
</li>
          <li>
            <strong>Amount Entered State:</strong> The terminal enters this state when the transaction
amount is entered. 
</li>
          <li>
            <strong>PIN Entered State:</strong> The terminal enters this state when the customer
enters their PIN. 
</li>
          <li>
            <strong>Processing Transaction State:</strong> The terminal enters this state when
it connects to a financial processor to process the transaction. 
</li>
          <li>
            <strong>Transaction Approved State:</strong> The terminal enters this state when the
transaction has been process and has been approved. 
</li>
          <li>
            <strong>Transaction Rejected State:</strong> The terminal enters this state when the
transaction was processed but was rejected.</li>
        </ul>
        <p>
Let's pretend the following is the client code that will use the point of sale terminal
to process transactions.
</p>
        <pre class="code">
          <span style="color: rgb(43,145,175)">IPosTerminal</span> terminal
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">PosTerminal</span>(
); terminal.SwipeCard( <span style="color: rgb(163,21,21)">"6278080000008205"</span> );
terminal.EnterAmount( 99.99 ); terminal.EnterPin( <span style="color: rgb(163,21,21)">"8012"</span> );
terminal.ProcessTransaction( ); terminal.PrintReceipt( );</pre>
        <p>
When the PosTerminal is first constructed it is immediate put into an Idle State which
displays an idle message to screen. The PosTerminal has a property of type IState
that all the concrete state types implement. 
</p>
        <p>
As actions are performed against the PosTerminal, they are delegated to the current
state.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">void</span> SwipeCard( <span style="color: rgb(0,0,255)">string</span> cardNumber
) { _currentState.SwipeCard( cardNumber ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> EnterAmount( <span style="color: rgb(0,0,255)">double</span> amount
) { _currentState.EnterAmount( amount ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> EnterPin( <span style="color: rgb(0,0,255)">string</span> pin
) { _currentState.EnterPin( pin ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> AuthorizeTransaction(
) { _currentState.ProcessTransaction( ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> PrintReceipt(
) { _currentState.PrintReceipt( ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> ProcessTransaction(
) { _currentState.ProcessTransaction( ); }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>In this implementation I've made it
the concrete state types responsibility to transition to the next state. For example
the IdleState might look like:<pre class="code"><span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> SwipeCard( <span style="color: rgb(0,0,255)">string</span> cardNumber
) { _terminal.Transaction = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">PosTransaction</span>(
); _terminal.Transaction.Date = <span style="color: rgb(43,145,175)">DateTime</span>.Now;
_terminal.Transaction.CardNumber = cardNumber; _terminal.CurrentState = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">CardSwipedState</span>(
_terminal ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> EnterAmount( <span style="color: rgb(0,0,255)">double</span> amount
) { <span style="color: rgb(43,145,175)">Console</span>.Out.WriteLine( <span style="color: rgb(163,21,21)">"Please
swipe a card first."</span> ); } </pre><p><a href="http://11011.net/software/vspaste"></a>...
</p><p>
With the state pattern you can re-order states and alter the implementation of a state
with out having to change the subject of the state.
</p><a href="http://mokhan.ca/blog/content/binary/DesignPatterns.State.zip">DesignPatterns.State.zip
(7.13 KB)</a><img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=603e6157-8879-4bfe-9135-46f875452fcf" /></body>
      <title>The State Pattern</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,603e6157-8879-4bfe-9135-46f875452fcf.aspx</guid>
      <link>http://mokhan.ca/blog/2007/08/26/The+State+Pattern.aspx</link>
      <pubDate>Sun, 26 Aug 2007 21:35:59 GMT</pubDate>
      <description>&lt;blockquote&gt; 
&lt;p&gt;
"The State Pattern allows an object to alter its behavior when its internal state
changes. The object will appear to change it's class." - Head First Design Pattern
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/115M5YwkVnL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Head First Design Patterns (Head First)&lt;/b&gt;
&lt;br&gt;
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596007124%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596007124%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Let's say I've got a point of sale terminal used for processing financial transactions.
Let's say that at any given time the terminal can be in 1 of 6 states. Those states
are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Idle State:&lt;/strong&gt; During this state an idle message is displayed on the
screen of the POS terminal. 
&lt;li&gt;
&lt;strong&gt;Card Swiped State:&lt;/strong&gt; The terminal enters this state when a card is
swiped. 
&lt;li&gt;
&lt;strong&gt;Amount Entered State:&lt;/strong&gt; The terminal enters this state when the transaction
amount is entered. 
&lt;li&gt;
&lt;strong&gt;PIN Entered State:&lt;/strong&gt; The terminal enters this state when the customer
enters their PIN. 
&lt;li&gt;
&lt;strong&gt;Processing Transaction State:&lt;/strong&gt; The terminal enters this state when
it connects to a financial processor to process the transaction. 
&lt;li&gt;
&lt;strong&gt;Transaction Approved State:&lt;/strong&gt; The terminal enters this state when the
transaction has been process and has been approved. 
&lt;li&gt;
&lt;strong&gt;Transaction Rejected State:&lt;/strong&gt; The terminal enters this state when the
transaction was processed but was rejected.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Let's pretend the following is the client code that will use the point of sale terminal
to process transactions.
&lt;/p&gt;
&lt;pre class="code"&gt;            &lt;span style="color: rgb(43,145,175)"&gt;IPosTerminal&lt;/span&gt; terminal
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;PosTerminal&lt;/span&gt;(
); terminal.SwipeCard( &lt;span style="color: rgb(163,21,21)"&gt;"6278080000008205"&lt;/span&gt; );
terminal.EnterAmount( 99.99 ); terminal.EnterPin( &lt;span style="color: rgb(163,21,21)"&gt;"8012"&lt;/span&gt; );
terminal.ProcessTransaction( ); terminal.PrintReceipt( );&lt;/pre&gt;
&lt;p&gt;
When the PosTerminal is first constructed it is immediate put into an Idle State which
displays an idle message to screen. The PosTerminal has a property of type IState
that all the concrete state types implement. 
&lt;/p&gt;
&lt;p&gt;
As actions are performed against the PosTerminal, they are delegated to the current
state.
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; SwipeCard( &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; cardNumber
) { _currentState.SwipeCard( cardNumber ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; EnterAmount( &lt;span style="color: rgb(0,0,255)"&gt;double&lt;/span&gt; amount
) { _currentState.EnterAmount( amount ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; EnterPin( &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; pin
) { _currentState.EnterPin( pin ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; AuthorizeTransaction(
) { _currentState.ProcessTransaction( ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; PrintReceipt(
) { _currentState.PrintReceipt( ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; ProcessTransaction(
) { _currentState.ProcessTransaction( ); }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;In this implementation I've made it
the concrete state types responsibility to transition to the next state. For example
the IdleState might look like:&lt;pre class="code"&gt;        &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; SwipeCard( &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; cardNumber
) { _terminal.Transaction = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;PosTransaction&lt;/span&gt;(
); _terminal.Transaction.Date = &lt;span style="color: rgb(43,145,175)"&gt;DateTime&lt;/span&gt;.Now;
_terminal.Transaction.CardNumber = cardNumber; _terminal.CurrentState = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;CardSwipedState&lt;/span&gt;(
_terminal ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; EnterAmount( &lt;span style="color: rgb(0,0,255)"&gt;double&lt;/span&gt; amount
) { &lt;span style="color: rgb(43,145,175)"&gt;Console&lt;/span&gt;.Out.WriteLine( &lt;span style="color: rgb(163,21,21)"&gt;"Please
swipe a card first."&lt;/span&gt; ); } &lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;...
&lt;/p&gt;
&lt;p&gt;
With the state pattern you can re-order states and alter the implementation of a state
with out having to change the&amp;nbsp;subject of&amp;nbsp;the state.
&lt;/p&gt;
&lt;a href="http://mokhan.ca/blog/content/binary/DesignPatterns.State.zip"&gt;DesignPatterns.State.zip
(7.13 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=603e6157-8879-4bfe-9135-46f875452fcf" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
      <category>Design Patterns</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=b564ebef-b28b-4f5d-8294-8fde3b7c49d0</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,b564ebef-b28b-4f5d-8294-8fde3b7c49d0.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <blockquote>
          <p>
"The Adapter Pattern converts the interface of a class into another interface the
clients expect. Adapter lets classes work together that couldn't otherwise because
of incompatible interfaces." - Head First Design Patterns
</p>
        </blockquote>
        <p>
          <table unselectable="on" border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/115M5YwkVnL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Head First Design Patterns (Head First)</b>
                  <br />
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596007124%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596007124%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
If you're trying to build a presentation layer that is platform agnostic, you might
turn to adapters for simple UI controls. For example in ASP.NET there is a drop down
list control, and in Win Forms there is the Combo Box control.
</p>
        <p>
A quick an easy adapter to the two controls might look like:
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span>
          <span style="color: rgb(0, 0, 255);">interface</span>
          <span style="color: rgb(43, 145, 175);">IDropDownListAdapter</span> { <span style="color: rgb(0, 0, 255);">void</span> BindTo( <span style="color: rgb(43, 145, 175);">IEnumerable</span>&lt; <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> &gt;
pairs ); <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> SelectedItem
{ <span style="color: rgb(0, 0, 255);">get</span>; } }</pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>Each drop down list item might look
like:
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span>
          <span style="color: rgb(0, 0, 255);">interface</span>
          <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> { <span style="color: rgb(0, 0, 255);">string</span> Text
{ <span style="color: rgb(0, 0, 255);">get</span>; } <span style="color: rgb(0, 0, 255);">string</span> Value
{ <span style="color: rgb(0, 0, 255);">get</span>; } }</pre>
        <p>
A concrete implementation for a Win Forms application might look like:
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span>
          <span style="color: rgb(0, 0, 255);">class</span>
          <span style="color: rgb(43, 145, 175);">DesktopDropDownList</span> : <span style="color: rgb(43, 145, 175);">IDropDownListAdapter</span> { <span style="color: rgb(0, 0, 255);">public</span> DesktopDropDownList( <span style="color: rgb(43, 145, 175);">ComboBox</span> dropDown
) { _dropDown = dropDown; _pairs = <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">Dictionary</span>&lt; <span style="color: rgb(0, 0, 255);">string</span>, <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> &gt;(
); } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">void</span> BindTo( <span style="color: rgb(43, 145, 175);">IEnumerable</span>&lt; <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> &gt;
pairs ) { <span style="color: rgb(0, 0, 255);">if</span> ( pairs != <span style="color: rgb(0, 0, 255);">null</span> )
{ _pairs = <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">Dictionary</span>&lt; <span style="color: rgb(0, 0, 255);">string</span>, <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> &gt;(
); <span style="color: rgb(0, 0, 255);">foreach</span> ( <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> pair <span style="color: rgb(0, 0, 255);">in</span> pairs
) { _dropDown.Items.Add( pair.Text ); _pairs.Add( pair.Text, pair ); } _dropDown.SelectedIndex
= 0; } } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(43, 145, 175);">IDropDownListItem</span> SelectedItem
{ <span style="color: rgb(0, 0, 255);">get</span> { <span style="color: rgb(0, 0, 255);">return</span> !<span style="color: rgb(0, 0, 255);">string</span>.IsNullOrEmpty(
_dropDown.Text ) ? _pairs[ _dropDown.Text ] : <span style="color: rgb(0, 0, 255);">null</span>;
} } <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(43, 145, 175);">ComboBox</span> _dropDown; <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(43, 145, 175);">IDictionary</span>&lt; <span style="color: rgb(0, 0, 255);">string</span>, <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> &gt;
_pairs; }</pre>
        <p>
A concrete implementation for a ASP.NET application might look like:
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span>
          <span style="color: rgb(0, 0, 255);">class</span>
          <span style="color: rgb(43, 145, 175);">WebDropDownList</span> : <span style="color: rgb(43, 145, 175);">IDropDownListAdapter</span> { <span style="color: rgb(0, 0, 255);">public</span> WebDropDownList( <span style="color: rgb(43, 145, 175);">DropDownList</span> dropDown
) { _dropDown = dropDown; } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">void</span> BindTo( <span style="color: rgb(43, 145, 175);">IEnumerable</span>&lt; <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> &gt;
pairs ) { <span style="color: rgb(0, 0, 255);">if</span> ( pairs != <span style="color: rgb(0, 0, 255);">null</span> )
{ <span style="color: rgb(0, 0, 255);">foreach</span> ( <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> pair <span style="color: rgb(0, 0, 255);">in</span> pairs
) { _dropDown.Items.Add( <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">ListItem</span>(
pair.Text, pair.Value ) ); } } } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(43, 145, 175);">IDropDownListItem</span> SelectedItem
{ <span style="color: rgb(0, 0, 255);">get</span> { <span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">DropDownListItem</span>(
_dropDown.SelectedItem.Text, _dropDown.SelectedItem.Value ); } } <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(43, 145, 175);">DropDownList</span> _dropDown;
}</pre>
        <p>
And voila... we can write a presentation layer that binds data to an IDropDownListAdapter,
without having to be specific to WinForms, ASP.NET, WPF, Silverlight etc.
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span> Presenter( <span style="color: rgb(43, 145, 175);">IView</span> view
) { _view = view; } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">void</span> Initialize(
) { <span style="color: rgb(43, 145, 175);">IList</span>&lt; <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> &gt;
items = <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">List</span>&lt; <span style="color: rgb(43, 145, 175);">IDropDownListItem</span> &gt;(
); items.Add( <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">DropDownListItem</span>( <span style="color: rgb(163, 21, 21);">"Yes"</span>, <span style="color: rgb(163, 21, 21);">"1"</span> )
); items.Add( <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(43, 145, 175);">DropDownListItem</span>( <span style="color: rgb(163, 21, 21);">"No"</span>, <span style="color: rgb(163, 21, 21);">"2"</span> )
); _view.AreYouHappy.BindTo( items ); }</pre>
        <a href="http://mokhan.ca/blog/content/binary/DesignPatterns.Adapter.zip">DesignPatterns.Adapter.zip
(4.56 KB)</a>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b564ebef-b28b-4f5d-8294-8fde3b7c49d0" />
      </body>
      <title>The Adapter Pattern</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,b564ebef-b28b-4f5d-8294-8fde3b7c49d0.aspx</guid>
      <link>http://mokhan.ca/blog/2007/08/26/The+Adapter+Pattern.aspx</link>
      <pubDate>Sun, 26 Aug 2007 20:39:14 GMT</pubDate>
      <description>&lt;blockquote&gt; 
&lt;p&gt;
"The Adapter Pattern converts the interface of a class into another interface the
clients expect. Adapter lets classes work together that couldn't otherwise because
of incompatible interfaces." - Head First Design Patterns
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;table unselectable="on" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/115M5YwkVnL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Head First Design Patterns (Head First)&lt;/b&gt;
&lt;br&gt;
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596007124%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596007124%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
If you're trying to build a presentation layer that is platform agnostic, you might
turn to adapters for simple UI controls. For example in ASP.NET there is a drop down
list control, and in Win Forms there is the Combo Box control.
&lt;/p&gt;
&lt;p&gt;
A quick an easy adapter to the two controls might look like:
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListAdapter&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; BindTo( &lt;span style="color: rgb(43, 145, 175);"&gt;IEnumerable&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; &amp;gt;
pairs ); &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; SelectedItem
{ &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt;; } }&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Each drop down list item might look
like:
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; Text
{ &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt;; } &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; Value
{ &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt;; } }&lt;/pre&gt;
&lt;p&gt;
A concrete implementation for a Win Forms application might look like:
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DesktopDropDownList&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListAdapter&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; DesktopDropDownList( &lt;span style="color: rgb(43, 145, 175);"&gt;ComboBox&lt;/span&gt; dropDown
) { _dropDown = dropDown; _pairs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Dictionary&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; &amp;gt;(
); } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; BindTo( &lt;span style="color: rgb(43, 145, 175);"&gt;IEnumerable&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; &amp;gt;
pairs ) { &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; ( pairs != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt; )
{ _pairs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Dictionary&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; &amp;gt;(
); &lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; ( &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; pair &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; pairs
) { _dropDown.Items.Add( pair.Text ); _pairs.Add( pair.Text, pair ); } _dropDown.SelectedIndex
= 0; } } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; SelectedItem
{ &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; !&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.IsNullOrEmpty(
_dropDown.Text ) ? _pairs[ _dropDown.Text ] : &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;
} } &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ComboBox&lt;/span&gt; _dropDown; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDictionary&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; &amp;gt;
_pairs; }&lt;/pre&gt;
&lt;p&gt;
A concrete implementation for a&amp;nbsp;ASP.NET application might look like:
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;WebDropDownList&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListAdapter&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; WebDropDownList( &lt;span style="color: rgb(43, 145, 175);"&gt;DropDownList&lt;/span&gt; dropDown
) { _dropDown = dropDown; } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; BindTo( &lt;span style="color: rgb(43, 145, 175);"&gt;IEnumerable&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; &amp;gt;
pairs ) { &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; ( pairs != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt; )
{ &lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; ( &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; pair &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; pairs
) { _dropDown.Items.Add( &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ListItem&lt;/span&gt;(
pair.Text, pair.Value ) ); } } } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; SelectedItem
{ &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DropDownListItem&lt;/span&gt;(
_dropDown.SelectedItem.Text, _dropDown.SelectedItem.Value ); } } &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DropDownList&lt;/span&gt; _dropDown;
}&lt;/pre&gt;
&lt;p&gt;
And voila... we can write a presentation layer that binds data to an IDropDownListAdapter,
without having to be specific to WinForms, ASP.NET, WPF, Silverlight etc.
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Presenter( &lt;span style="color: rgb(43, 145, 175);"&gt;IView&lt;/span&gt; view
) { _view = view; } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Initialize(
) { &lt;span style="color: rgb(43, 145, 175);"&gt;IList&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; &amp;gt;
items = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;List&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDropDownListItem&lt;/span&gt; &amp;gt;(
); items.Add( &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DropDownListItem&lt;/span&gt;( &lt;span style="color: rgb(163, 21, 21);"&gt;"Yes"&lt;/span&gt;, &lt;span style="color: rgb(163, 21, 21);"&gt;"1"&lt;/span&gt; )
); items.Add( &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DropDownListItem&lt;/span&gt;( &lt;span style="color: rgb(163, 21, 21);"&gt;"No"&lt;/span&gt;, &lt;span style="color: rgb(163, 21, 21);"&gt;"2"&lt;/span&gt; )
); _view.AreYouHappy.BindTo( items ); }&lt;/pre&gt;
&lt;a href="http://mokhan.ca/blog/content/binary/DesignPatterns.Adapter.zip"&gt;DesignPatterns.Adapter.zip
(4.56 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b564ebef-b28b-4f5d-8294-8fde3b7c49d0" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
      <category>Design Patterns</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=76607228-2b07-45da-bc95-ec246854352a</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,76607228-2b07-45da-bc95-ec246854352a.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <blockquote>
          <p>
"Every craftsman starts his or her journey with a basic set of good-quality tools.
A woodworker might need rules, gauges, a couple of saws, some good planes, fine chisels,
drills and braces, mallets, and clamps. These tools will be lovingly chosen, will
be built to last, will perform specific jobs with little overlap with other tools,
and, perhaps most importantly, will feel right in the budding woodworker's hands."
</p>
        </blockquote>
        <p>
I read the above paragraph from the pragmatic programmer, and thought it made a lot
of sense. My appreciation for tools continues to grow, and grow. And as I learn to
use different tools, I find different sorts of productivity gains.
</p>
        <p>
Some of the tools I use:
</p>
        <ul>
          <li>
            <a href="http://www.jetbrains.com/resharper/">ReSharper</a>
          </li>
          <li>
            <a href="http://www.mbunit.com/">MbUnit</a> (recently switched from <a href="http://www.nunit.org/">NUnit</a>) 
</li>
          <li>
            <a href="http://nant.sourceforge.net/">NAnt</a>
          </li>
          <li>
            <a href="http://www.aisto.com/roeder/dotnet/">Reflector</a>
          </li>
          <li>
            <a href="http://www.sliver.com/dotnet/SnippetCompiler/">Snippet Compiler</a>
          </li>
          <li>
            <a href="http://www.stack.nl/~dimitri/doxygen/">Doxygen</a>
          </li>
          <li>
            <a href="http://www.launchy.net/">Launchy</a>
          </li>
          <li>
            <a href="http://www.truecrypt.org/">TrueCrypt</a>
          </li>
          <li>
            <a href="https://secure.logmein.com/products/hamachi/vpn.asp?lang=en">Hamachi</a>
          </li>
          <li>
            <a href="http://notepad-plus.sourceforge.net/uk/site.htm">Notepad++</a>
          </li>
          <li>
            <a href="http://www.gotdotnet.com/Team/FxCop/">FxCop</a>
          </li>
        </ul>
        <p>
 
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://g-ec2.images-amazon.com/images/I/01cou4t7hiL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>The Pragmatic Programmer: From Journeyman to Master</b>
                  <br />
by Andrew Hunt, David Thomas<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=020161622X%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/020161622X%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=76607228-2b07-45da-bc95-ec246854352a" />
      </body>
      <title>Good Quality Tools</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,76607228-2b07-45da-bc95-ec246854352a.aspx</guid>
      <link>http://mokhan.ca/blog/2007/08/23/Good+Quality+Tools.aspx</link>
      <pubDate>Thu, 23 Aug 2007 13:29:00 GMT</pubDate>
      <description>&lt;blockquote&gt; 
&lt;p&gt;
"Every craftsman starts his or her journey with a basic set of good-quality tools.
A woodworker might need rules, gauges, a couple of saws, some good planes, fine chisels,
drills and braces, mallets, and clamps. These tools will be lovingly chosen, will
be built to last, will perform specific jobs with little overlap with other tools,
and, perhaps most importantly, will feel right in the budding woodworker's hands."
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I read the above paragraph from the pragmatic programmer, and thought it made a lot
of sense. My appreciation for tools continues to grow, and grow. And as I learn to
use different tools, I find different sorts of productivity gains.
&lt;/p&gt;
&lt;p&gt;
Some of the tools I use:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.jetbrains.com/resharper/"&gt;ReSharper&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://www.mbunit.com/"&gt;MbUnit&lt;/a&gt; (recently switched from &lt;a href="http://www.nunit.org/"&gt;NUnit&lt;/a&gt;) 
&lt;li&gt;
&lt;a href="http://nant.sourceforge.net/"&gt;NAnt&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://www.sliver.com/dotnet/SnippetCompiler/"&gt;Snippet Compiler&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://www.stack.nl/~dimitri/doxygen/"&gt;Doxygen&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://www.launchy.net/"&gt;Launchy&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://www.truecrypt.org/"&gt;TrueCrypt&lt;/a&gt; 
&lt;li&gt;
&lt;a href="https://secure.logmein.com/products/hamachi/vpn.asp?lang=en"&gt;Hamachi&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://notepad-plus.sourceforge.net/uk/site.htm"&gt;Notepad++&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://www.gotdotnet.com/Team/FxCop/"&gt;FxCop&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://g-ec2.images-amazon.com/images/I/01cou4t7hiL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;The Pragmatic Programmer: From Journeyman to Master&lt;/b&gt;
&lt;br&gt;
by Andrew Hunt, David Thomas&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=020161622X%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/020161622X%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=76607228-2b07-45da-bc95-ec246854352a" /&gt;</description>
      <category>Books</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=df1b7a0f-7e6b-4276-abc9-6dba6efc131d</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,df1b7a0f-7e6b-4276-abc9-6dba6efc131d.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I think Martin Fowlers description of optimistic and pessimistic locking is excellent.
So excellent that I had to share...
</p>
        <blockquote>
          <p>
"Let's suppose that Martin and David both want to edit the Customer file at the same
time. With optimistic locking both of them can make a copy of the file and edit it
freely. If David is the first to finish, he can check in his work without trouble.
The concurrency control kicks in when Martin tries to commit his changes. At this
point the source code control system detects a conflict between Martin's changes and
David's changes. Martin's commit is rejected and it's up to him to figure out how
to deal with the situation. With pessimistic locking whoever checks out the file first
prevents anyone else from editing it. So if Martin is first to check out, David can't
work with the file until Martin is finished with it and commits his changes." - Martin
Fowler : PoEAA
</p>
        </blockquote>
        <p>
SVN of course uses optimistic locking and Microsoft Visual Source Safe uses pessimistic
locking. I've become a huge fan of SVN recently, and since we started using it here
at work, I feel like I've become more productive. Gone are the days when I would hear <strong>"Can
you check in the project, I need to add a file."</strong>, <strong>"Where's &lt;enter
name&gt;? He's not in today? But he's got a file checked out that I need."</strong></p>
        <p>
 
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/01SK85BS8EL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Patterns of Enterprise Application Architecture</b>
                  <br />
by Martin Fowler<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321127420%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321127420%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=df1b7a0f-7e6b-4276-abc9-6dba6efc131d" />
      </body>
      <title>The Difference Between SVN and Visual Source Safe</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,df1b7a0f-7e6b-4276-abc9-6dba6efc131d.aspx</guid>
      <link>http://mokhan.ca/blog/2007/08/22/The+Difference+Between+SVN+And+Visual+Source+Safe.aspx</link>
      <pubDate>Wed, 22 Aug 2007 19:11:45 GMT</pubDate>
      <description>&lt;p&gt;
I think Martin Fowlers description of optimistic and pessimistic locking is excellent.
So excellent that I had to share...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"Let's suppose that Martin and David both want to edit the Customer file at the same
time. With optimistic locking both of them can make a copy of the file and edit it
freely. If David is the first to finish, he can check in his work without trouble.
The concurrency control kicks in when Martin tries to commit his changes. At this
point the source code control system detects a conflict between Martin's changes and
David's changes. Martin's commit is rejected and it's up to him to figure out how
to deal with the situation. With pessimistic locking whoever checks out the file first
prevents anyone else from editing it. So if Martin is first to check out, David can't
work with the file until Martin is finished with it and commits his changes." - Martin
Fowler : PoEAA
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
SVN of course uses optimistic locking and Microsoft Visual Source Safe uses pessimistic
locking. I've become a huge fan of SVN recently, and since we started using it here
at work, I feel like I've become more productive. Gone are the days when I would hear &lt;strong&gt;"Can
you check in the project, I need to add a file."&lt;/strong&gt;, &lt;strong&gt;"Where's &amp;lt;enter
name&amp;gt;? He's not in today? But he's got a file checked out that I need."&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/01SK85BS8EL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Patterns of Enterprise Application Architecture&lt;/b&gt;
&lt;br&gt;
by Martin Fowler&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321127420%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321127420%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=df1b7a0f-7e6b-4276-abc9-6dba6efc131d" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=b53870e2-3cfc-4d36-988b-b706d77533b5</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,b53870e2-3cfc-4d36-988b-b706d77533b5.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <blockquote>
          <p>
"A process is a, usually heavyweight, execution context that provides a lot of isolation
for the internal data it works on. A thread is a lighter-weight active agent that's
set up so that multiple threads can operate in a single process. " - Martin Fowler :
PoEAA
</p>
        </blockquote>
        <p>
 
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/01SK85BS8EL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Patterns of Enterprise Application Architecture</b>
                  <br />
by Martin Fowler<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321127420%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321127420%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b53870e2-3cfc-4d36-988b-b706d77533b5" />
      </body>
      <title>Processes and Threads</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,b53870e2-3cfc-4d36-988b-b706d77533b5.aspx</guid>
      <link>http://mokhan.ca/blog/2007/08/22/Processes+And+Threads.aspx</link>
      <pubDate>Wed, 22 Aug 2007 18:51:57 GMT</pubDate>
      <description>&lt;blockquote&gt; 
&lt;p&gt;
"A process is a, usually heavyweight, execution context that provides a lot of isolation
for the internal data it works on. A thread is a lighter-weight active agent that's
set up so that multiple threads can operate in a single process. " - Martin Fowler&amp;nbsp;:
PoEAA
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/01SK85BS8EL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Patterns of Enterprise Application Architecture&lt;/b&gt;
&lt;br&gt;
by Martin Fowler&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321127420%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321127420%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=b53870e2-3cfc-4d36-988b-b706d77533b5" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=38d215d3-e232-4f58-8ec9-be1651b1399a</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,38d215d3-e232-4f58-8ec9-be1651b1399a.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In geometry, when two lines are orthogonal if they meet at right angles,
such as the axes on a Cartesian plain. Move along one of the axes, and your position
projected onto the other doesn't change.
</p>
        <blockquote>
          <p>
In computing, the term has come to signify a kind of independence or decoupling. Two
or more things are orthogonal if changes in one do not affect any of the others. 
</p>
        </blockquote>
        <p>
In a well-designed system, the database code will be orthogonal to the user interface;
you can change the interface without affecting the database, and swap databases without
changing the interface.
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://g-ec2.images-amazon.com/images/I/01cou4t7hiL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>The Pragmatic Programmer: From Journeyman to Master</b>
                  <br />
by Andrew Hunt, David Thomas<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=020161622X%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/020161622X%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=38d215d3-e232-4f58-8ec9-be1651b1399a" />
      </body>
      <title>What is Orthogonality?</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,38d215d3-e232-4f58-8ec9-be1651b1399a.aspx</guid>
      <link>http://mokhan.ca/blog/2007/08/22/What+Is+Orthogonality.aspx</link>
      <pubDate>Wed, 22 Aug 2007 18:42:09 GMT</pubDate>
      <description>&lt;p&gt;
In geometry,&amp;nbsp;when&amp;nbsp;two lines are orthogonal if they meet at right angles,
such as the axes on a&amp;nbsp;Cartesian plain. Move along one of the axes, and your position
projected onto the other doesn't change.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
In computing, the term has come to signify a kind of independence or decoupling. Two
or more things are orthogonal if changes in one do not affect any of the others. 
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
In a well-designed system, the database code will be orthogonal to the user interface;
you can change the interface without affecting the database, and swap databases without
changing the interface.
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://g-ec2.images-amazon.com/images/I/01cou4t7hiL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;The Pragmatic Programmer: From Journeyman to Master&lt;/b&gt;
&lt;br&gt;
by Andrew Hunt, David Thomas&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=020161622X%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/020161622X%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=38d215d3-e232-4f58-8ec9-be1651b1399a" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=e718cff0-1b49-44a7-b331-df975204b68f</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,e718cff0-1b49-44a7-b331-df975204b68f.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So I recently finished reading...
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/11JY4FXVWAL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Test Driven Development: By Example (Addison-Wesley Signature Series)</b>
                  <br />
by Kent Beck<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321146530%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321146530%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
This was an awesome read! It started off with some a great example written in Java
on Money. It was great to start right from the beginning and drive out the design
with tests. Over the course of the book you see the design evolve and grow in to something,
some might call "SEXY"!
</p>
        <p>
Part 2 of the book starts to drive out an xUnit framework using TDD. It was pretty
cool, and definitely gave me some insight as to how unit test frameworks like NUnit,
and MbUnit work. 
</p>
        <p>
Part 3 of the book discusses Patterns for Test Driven Development and how to drive
out good OO design in your application and tests. I had a bit of trouble getting
over the Python syntax used in parts 2 and 3 of the book, but it's definitely good
to get some exposure to different languages. (Those crazy python guys!)
</p>
        <p>
Anyway's, this book is definitely worth checking out! I cant wait to read XP Explained
by Beck!
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=e718cff0-1b49-44a7-b331-df975204b68f" />
      </body>
      <title>What do you mean you test first?</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,e718cff0-1b49-44a7-b331-df975204b68f.aspx</guid>
      <link>http://mokhan.ca/blog/2007/08/03/What+Do+You+Mean+You+Test+First.aspx</link>
      <pubDate>Fri, 03 Aug 2007 08:14:39 GMT</pubDate>
      <description>&lt;p&gt;
So I recently finished reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/11JY4FXVWAL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Test Driven Development: By Example (Addison-Wesley Signature Series)&lt;/b&gt;
&lt;br&gt;
by Kent Beck&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0321146530%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321146530%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
This was an awesome read! It started off with some a great example written in Java
on Money. It was great to start right from the beginning and drive out the design
with tests. Over the course of the book you see the design evolve and grow in to something,
some might call "SEXY"!
&lt;/p&gt;
&lt;p&gt;
Part 2 of the book starts to drive out an xUnit framework using TDD. It was pretty
cool, and definitely gave me some insight as to how unit test frameworks like NUnit,
and MbUnit work. 
&lt;/p&gt;
&lt;p&gt;
Part 3 of the book discusses Patterns for Test Driven Development and how to drive
out good OO design in your application and tests. I&amp;nbsp;had a bit of trouble getting
over the Python syntax used in parts 2 and 3 of the book, but it's definitely good
to get some exposure to different languages. (Those crazy python guys!)
&lt;/p&gt;
&lt;p&gt;
Anyway's, this book is definitely worth checking out! I cant wait to read XP Explained
by Beck!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=e718cff0-1b49-44a7-b331-df975204b68f" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=6cf2c588-91f2-439d-afb2-f6af9f59bad6</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,6cf2c588-91f2-439d-afb2-f6af9f59bad6.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Good Morning! So this week during my dead time on the bus I have been reading...
</p>
        <p>
          <table border="0" unselectable="on">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://g-ec2.images-amazon.com/images/I/01cou4t7hiL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>The Pragmatic Programmer: From Journeyman to Master</b>
                  <br />
by Andrew Hunt, David Thomas<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=020161622X%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/020161622X%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
 
</p>
        <p>
This book is great! It's a short one, but I seem to be taking my time with this one.
It speaks at a much higher level, not so specific to a certain technology or language.
However, the code samples in this book are mostly in C, Java and Perl. It's pretty
cool to get some exposure to other languages, especially Perl!
</p>
        <p>
Things I really like most about this book are the quotes and analogies. The analogies
and stories seem to make it so much easier to understand and relate to different concepts.
Stone soup and boiled frogs are great examples!
</p>
        <p>
The bus ride was nice today, I managed to scoop a seat in the far back next to the
window which offers me a little more privacy and great lighting for reading. 
</p>
        <p>
Did I mention that it's Friday? 
</p>
        <p>
GET BACK TO WORK!
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=6cf2c588-91f2-439d-afb2-f6af9f59bad6" />
      </body>
      <title>What Does Pragmatic Mean?</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,6cf2c588-91f2-439d-afb2-f6af9f59bad6.aspx</guid>
      <link>http://mokhan.ca/blog/2007/07/27/What+Does+Pragmatic+Mean.aspx</link>
      <pubDate>Fri, 27 Jul 2007 20:27:14 GMT</pubDate>
      <description>&lt;p&gt;
Good Morning! So this week during my dead time on the bus I have been reading...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://g-ec2.images-amazon.com/images/I/01cou4t7hiL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;The Pragmatic Programmer: From Journeyman to Master&lt;/b&gt;
&lt;br&gt;
by Andrew Hunt, David Thomas&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=020161622X%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/020161622X%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This book is great! It's a short one, but I seem to be taking my time with this one.
It speaks at a much higher level, not so specific to a certain technology or language.
However, the code samples in this book are mostly in C, Java and Perl. It's pretty
cool to get some exposure to other languages, especially Perl!
&lt;/p&gt;
&lt;p&gt;
Things I really like most about this book are the quotes and analogies. The analogies
and stories seem to make it so much easier to understand and relate to different concepts.
Stone soup and boiled frogs are great examples!
&lt;/p&gt;
&lt;p&gt;
The bus ride was nice today, I managed to scoop a seat in the far back next to the
window which offers me a little more privacy and great lighting for reading. 
&lt;/p&gt;
&lt;p&gt;
Did I mention that it's Friday? 
&lt;/p&gt;
&lt;p&gt;
GET BACK TO WORK!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=6cf2c588-91f2-439d-afb2-f6af9f59bad6" /&gt;</description>
      <category>Books</category>
      <category>Journal</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=d5fa468f-9abb-44c0-bb1b-8ce2d31ef725</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,d5fa468f-9abb-44c0-bb1b-8ce2d31ef725.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Earlier this week I finished reading "Code Complete" by Steve McConnell. I have to
admin that everyone who has ever recommended reading this book, was absolutely correct
for doing so. It's about 860 pages long, and it's worth reading every word. What I
found this book did for me was help me to reflect on my last 3 years of software development. 
</p>
        <p>
Early in my software construction career, a wise programmer handed me his copy of
"Code Complete" and told me I might be interested in reading it. I thumbed through
the pages but didn't really give it a fair try. I just wasn't interested in a book
that talked about programming but showed very little source code. (At that time it
was all about C programming for me). Man, I was a silly kid, if I had just listened
to the wise programmer who handed me the book!
</p>
        <p>
As I was read through the book, there were many times where I felt like "I remember
being in a situation like that", or "That's so true, I never thought about it
like that." It was excellent and I recommend it to anyone who is currently involved
in software construction.
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/014VXABM8BL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Code Complete, Second Edition</b>
                  <br />
by Steve McConnell<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0735619670%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0735619670%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
Here's a list of some of my favorite quotes from the book.
</p>
        <blockquote>
          <p>
"Programmers like Global Gary, who litter their code with defects and "complete" their
programs quickly, are rewarded more than programmers like High-Quality Henry, who
write excellent programs and make sure that they are usable before releasing them."
</p>
        </blockquote>
        <blockquote>
          <p>
"Testing's goal runs counter to the goals of other development activities. The goal
is to find errors. A successful test is one that breaks the software. The goal of
every other development activity is to prevent errors and keep the software from breaking."
</p>
        </blockquote>
        <blockquote>
          <p>
"Developers sometimes wonder whether it's better to write test cases after the code
has been written of beforehand (Beck 2003). The defect-cost increase graph suggests
that writing test cases first will minimize the amount of time between when a defect
is inserted into the code and when the defect is detected and removed. This turns
out to be one of many reasons to write test cases first:"
</p>
        </blockquote>
        <blockquote>
          <p>
"... confirm another version of the General Principle of Software Quality: it's cheaper
to build high-quality software than it is to build and fix low-quality software."
</p>
        </blockquote>
        <blockquote>
          <p>
"The term 'scaffolding' comes from building construction. Scaffolding is built so
that workers can reach parts of a building they couldn't reach otherwise. Software
scaffolding is built for the sole purpose of making it easy to exercise code."
</p>
        </blockquote>
        <blockquote>
          <p>
"Before you fix a problem, make sure you understand it to the core. Triangulate the
defect both with cases that should reproduce the error and with cases that shouldn't
reproduce the error. Keep at it until you understand the problem well enough to predict
its occurrence correctly every time."
</p>
        </blockquote>
        <blockquote>
          <p>
"A class has poor cohesion: If you find a class that takes ownership for a hodgepodge
of unrelated responsibilities, that class should be broken up into multiple classes,
each of which has responsibility for a cohesive set of responsibilities."
</p>
        </blockquote>
        <blockquote>
          <p>
"Requirements for the 'design ahead' code haven't been fully developed, which means
the programmer will likely guess wrong about those future requirements. The 'code
ahead' work will ultimately be thrown away."
</p>
        </blockquote>
        <blockquote>
          <p>
"Return as soon as you known the answer instead of assigning a return value within
nested if-then-else statements: Code is often easiest to read and least error-prone
if you exit a routine as soon as you know the return value. The alternative of setting
a return value and then unwinding your way through a lot of logic can be harder to
follow."
</p>
        </blockquote>
        <blockquote>
          <p>
"One of my former roommates was a great procrastinator. He justified his laziness
by saying that many of the things people feel rushed to do simply don't need to be
done. If he waited long enough, he claimed, the things that weren't important would
be procrastinated into oblivion and he wouldn't waste his time doing them... Lazy
evaluation is similar to just-in-time strategies that do the work closest to when
it's needed."
</p>
        </blockquote>
        <blockquote>
          <p>
"Code that receives an award should be exceptionally good. If you give an award to
a programmer everyone else knows does bad work, you look like Homer Simpson trying
to run a nuclear reactor."
</p>
        </blockquote>
        <blockquote>
          <p>
"If you implement each change as it occurs to you, you'll soon find yourself walking
on a software treadmill - for all that the system will be changing, it won't be moving
closer to completion."
</p>
        </blockquote>
        <blockquote>
          <p>
"A significant percentage of the projects that are perceived to be late would actually
be on time if they accounted for the impact of untracked but agreed-upon changes.
Poor change control allows changes to accumulate off the books, which undermines status
visibility, long-range predictability, project planning, risk management specifically,
and project management generally."
</p>
        </blockquote>
        <blockquote>
          <p>
"The implication for recruiting and hiring is clear. If you have to pay more to get
a top-10-percent programmer rather than a bottom-10-percent programmer, jump at the
chance. You'll get an immediate payoff in the quality and productivity of the programmer
you hire, and you'll get a residual effect in the quality and productivity of the
other programmers your organization is able to retain because good programmers tend
to cluster."
</p>
        </blockquote>
        <blockquote>
          <p>
"If you construct and integrate software in the wrong order, it's harder to code,
harder to test, and harder to debug. If none of it will work until all of it works,
it can seem as though it will never be finished."
</p>
        </blockquote>
        <blockquote>
          <p>
"When code is integrated and running, even if the system isn't usable, it's apparent
that it soon will be. With incremental integration, programmers see early results
from their work, so their morale is better than when they suspect that their project
will never draw its first breath."
</p>
        </blockquote>
        <blockquote>
          <p>
"The visual and intellectual enjoyment of well-formatted code is a pleasure that few
nonprogrammer's can appreciate. But programmers who take pride in their work derive
great artistic satisfaction from polishing the visual structure of their code."
</p>
        </blockquote>
        <blockquote>
          <p>
"When someone says, 'This is really tricky code," I hear them say, "This is really
bad code." If something seems tricky to you, it will be incomprehensible to someone
else. Even something that doesn't seem all that tricky to you can seem impossibly
convoluted to another person who hasn't seen the trick before."
</p>
        </blockquote>
        <blockquote>
          <p>
"Your employer can't force you to be a good programmer; a lot of times your employer
isn't even in a position to judge whether you're good. If you want to be great, you're
responsible for making yourself great. It's a matter of your personal character."
</p>
        </blockquote>
        <blockquote>
          <p>
"The people who are best at programming are the people who realize how small their
brains are. They are humble. The people who are the worst at programming are the people
who refuse to accept the fact that their brains aren't equal to the task. Their egos
keep them from being great programmers."
</p>
        </blockquote>
        <blockquote>
          <p>
"... humble programmers who compensate for their fallibilities write code that's easier
for themselves and others to understand and that has fewer errors."
</p>
        </blockquote>
        <blockquote>
          <p>
"Adherence to a single method is also harmful in that it makes you force-fit the problem
to the solution. If you decide on the solution method before you fully understand
the problem, you act prematurely. Over-constrain the set of possible solutions, and
you might rule out the most effective solution."
</p>
        </blockquote>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=d5fa468f-9abb-44c0-bb1b-8ce2d31ef725" />
      </body>
      <title>The Complete Code Book</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,d5fa468f-9abb-44c0-bb1b-8ce2d31ef725.aspx</guid>
      <link>http://mokhan.ca/blog/2007/07/14/The+Complete+Code+Book.aspx</link>
      <pubDate>Sat, 14 Jul 2007 02:47:31 GMT</pubDate>
      <description>&lt;p&gt;
Earlier this week I finished reading "Code Complete" by Steve McConnell. I have to
admin that everyone who has ever recommended reading this book, was absolutely correct
for doing so. It's about 860 pages long, and it's worth reading every word. What I
found this book did for me was help me to reflect on my last 3 years of software development. 
&lt;/p&gt;
&lt;p&gt;
Early in my software construction career, a wise programmer handed me his copy of
"Code Complete" and told me I might be interested in reading it. I thumbed through
the pages but didn't really give it a fair try. I just wasn't interested in a book
that talked about programming but showed very little source code. (At that time it
was all about C programming for me). Man, I was a silly kid, if I had just listened
to the wise programmer who handed me the book!
&lt;/p&gt;
&lt;p&gt;
As I was read through&amp;nbsp;the book, there were many times where I felt like "I remember
being in a situation like that", or&amp;nbsp;"That's so true, I never thought about it
like that." It was excellent and I recommend it to anyone who is currently involved
in software construction.
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/014VXABM8BL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Code Complete, Second Edition&lt;/b&gt;
&lt;br&gt;
by Steve McConnell&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0735619670%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0735619670%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
Here's a list of some of my favorite quotes from the book.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"Programmers like Global Gary, who litter their code with defects and "complete" their
programs quickly, are rewarded more than programmers like High-Quality Henry, who
write excellent programs and make sure that they are usable before releasing them."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"Testing's goal runs counter to the goals of other development activities. The goal
is to find errors. A successful test is one that breaks the software. The goal of
every other development activity is to prevent errors and keep the software from breaking."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"Developers sometimes wonder whether it's better to write test cases after the code
has been written of beforehand (Beck 2003). The defect-cost increase graph suggests
that writing test cases first will minimize the amount of time between when a defect
is inserted into the code and when the defect is detected and removed. This turns
out to be one of many reasons to write test cases first:"
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"... confirm another version of the General Principle of Software Quality: it's cheaper
to build high-quality software than it is to build and fix low-quality software."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"The term 'scaffolding' comes from building construction. Scaffolding is built so
that workers can reach parts of a building they couldn't reach otherwise. Software
scaffolding is built for the sole purpose of making it easy to exercise code."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"Before you fix a problem, make sure you understand it to the core. Triangulate the
defect both with cases that should reproduce the error and with cases that shouldn't
reproduce the error. Keep at it until you understand the problem well enough to predict
its occurrence correctly every time."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"A class has poor cohesion: If you find a class that takes ownership for a hodgepodge
of unrelated responsibilities, that class should be broken up into multiple classes,
each of which has responsibility for a cohesive set of responsibilities."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"Requirements for the 'design ahead' code haven't been fully developed, which means
the programmer will likely guess wrong about those future requirements. The 'code
ahead' work will ultimately be thrown away."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"Return as soon as you known the answer instead of assigning a return value within
nested if-then-else statements: Code is often easiest to read and least error-prone
if you exit a routine as soon as you know the return value. The alternative of setting
a return value and then unwinding your way through a lot of logic can be harder to
follow."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"One of my former roommates was a great procrastinator. He justified his laziness
by saying that many of the things people feel rushed to do simply don't need to be
done. If he waited long enough, he claimed, the things that weren't important would
be procrastinated into oblivion and he wouldn't waste his time doing them... Lazy
evaluation is similar to just-in-time strategies that do the work closest to when
it's needed."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"Code that receives an award should be exceptionally good. If you give an award to
a programmer everyone else knows does bad work, you look like Homer Simpson trying
to run a nuclear reactor."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"If you implement each change as it occurs to you, you'll soon find yourself walking
on a software treadmill - for all that the system will be changing, it won't be moving
closer to completion."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"A significant percentage of the projects that are perceived to be late would actually
be on time if they accounted for the impact of untracked but agreed-upon changes.
Poor change control allows changes to accumulate off the books, which undermines status
visibility, long-range predictability, project planning, risk management specifically,
and project management generally."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"The implication for recruiting and hiring is clear. If you have to pay more to get
a top-10-percent programmer rather than a bottom-10-percent programmer, jump at the
chance. You'll get an immediate payoff in the quality and productivity of the programmer
you hire, and you'll get a residual effect in the quality and productivity of the
other programmers your organization is able to retain because good programmers tend
to cluster."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"If you construct and integrate software in the wrong order, it's harder to code,
harder to test, and harder to debug. If none of it will work until all of it works,
it can seem as though it will never be finished."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"When code is integrated and running, even if the system isn't usable, it's apparent
that it soon will be. With incremental integration, programmers see early results
from their work, so their morale is better than when they suspect that their project
will never draw its first breath."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"The visual and intellectual enjoyment of well-formatted code is a pleasure that few
nonprogrammer's can appreciate. But programmers who take pride in their work derive
great artistic satisfaction from polishing the visual structure of their code."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"When someone says, 'This is really tricky code," I hear them say, "This is really
bad code." If something seems tricky to you, it will be&amp;nbsp;incomprehensible to someone
else. Even something that doesn't seem all that tricky to you can seem impossibly
convoluted to another person who hasn't seen the trick before."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"Your employer can't force you to be a good programmer; a lot of times your employer
isn't even in a position to judge whether you're good. If you want to be great, you're
responsible for making yourself great. It's a matter of your personal character."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"The people who are best at programming are the people who realize how small their
brains are. They are humble. The people who are the worst at programming are the people
who refuse to accept the fact that their brains aren't equal to the task. Their egos
keep them from being great programmers."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"... humble programmers who compensate for their fallibilities write code that's easier
for themselves and others to understand and that has fewer errors."
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
"Adherence to a single method is also harmful in that it makes you force-fit the problem
to the solution. If you decide on the solution method before you fully understand
the problem, you act prematurely. Over-constrain the set of possible solutions, and
you might rule out the most effective solution."
&lt;/p&gt;
&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=d5fa468f-9abb-44c0-bb1b-8ce2d31ef725" /&gt;</description>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=084dadee-8059-4812-817c-54b2084537b6</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,084dadee-8059-4812-817c-54b2084537b6.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
For anyone who currently writes C#, or is looking to start I highly recommend you
pick up a copy of... 
</p>
        <blockquote>
          <p>
            <table border="0">
              <tbody>
                <tr>
                  <td valign="top">
                    <img src="http://g-ec2.images-amazon.com/images/I/01J2SZEVA2L.jpg" border="1" />
                  </td>
                  <td valign="top">
                    <b>The Elements of C# Style</b>
                    <br />
by Kenneth Baldwin, Andrew Gray, Trevor Misfeldt<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0521671590%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0521671590%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
                </tr>
              </tbody>
            </table>
          </p>
        </blockquote>
        <p>
This book offers great suggestions for programming style in the C# language. It covers
things like:
</p>
        <ul>
          <li>
Formatting 
</li>
          <li>
Naming Conventions 
</li>
          <li>
Documentation 
</li>
          <li>
General Principles</li>
        </ul>
        <p>
The book contains a series of rules to abide by, most of the rules are quite flexible.
The main premise of the book is to maintain consistency but offers variations that
a C# developer can follow.
</p>
        <p>
Here are a few example's taken from the book:
</p>
        <blockquote>
          <p>
            <em>43. Use Came Case for Variable and Method Parameter Names</em>
          </p>
          <p>
            <em>Use lowercase for the first word and capitalize each subsequent word that appears
in a variable name to provide a visual cue for separating the individual words within
each name.</em>
          </p>
          <pre>
            <span style="color: blue">public</span>
            <span style="color: blue">class</span> Customer
{ <span style="color: blue">public</span><span style="color: blue">string</span> firstName_; <span style="color: blue">public</span><span style="color: blue">string</span> lastName_; <span style="color: blue">public</span><span style="color: blue">string</span> ToString(){ <span style="color: blue">return</span> lastName_
+ <span style="color: maroon">", "</span> + firstName_; } } </pre>
        </blockquote>
        <blockquote>
          <p>
            <em>49. Use an Organization Name for the Root Namespace, and Narrow by Project, Product
or Group</em>
          </p>
          <pre>
            <span style="color: blue">namespace</span> Company.Group.Project{ <span style="color: green">//
...</span> }</pre>
        </blockquote>
        <p>
This book is an extremely quick read, but well worth the price. It comes in handy
as an excellent reference manual!
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=084dadee-8059-4812-817c-54b2084537b6" />
      </body>
      <title>Do You Have Style?</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,084dadee-8059-4812-817c-54b2084537b6.aspx</guid>
      <link>http://mokhan.ca/blog/2007/07/09/Do+You+Have+Style.aspx</link>
      <pubDate>Mon, 09 Jul 2007 02:28:20 GMT</pubDate>
      <description>&lt;p&gt;
For anyone who currently writes C#, or is looking to start I highly recommend you
pick up a copy of...&amp;nbsp;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://g-ec2.images-amazon.com/images/I/01J2SZEVA2L.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;The Elements of C# Style&lt;/b&gt;
&lt;br&gt;
by Kenneth Baldwin, Andrew Gray, Trevor Misfeldt&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0521671590%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0521671590%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
This book offers great suggestions for programming style in the C# language. It covers
things like:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Formatting 
&lt;li&gt;
Naming Conventions 
&lt;li&gt;
Documentation 
&lt;li&gt;
General Principles&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The book contains a series of rules to abide by, most of the rules are quite flexible.
The main premise of the book is to maintain consistency but offers variations that
a C# developer can follow.
&lt;/p&gt;
&lt;p&gt;
Here are a&amp;nbsp;few example's taken from the book:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;em&gt;43. Use Came Case for Variable and Method Parameter Names&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;Use lowercase for the first word and capitalize each subsequent word that appears
in a variable name to provide a visual cue for separating the individual words within
each name.&lt;/em&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; Customer
{ &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; firstName_; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; lastName_; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; ToString(){ &lt;span style="color: blue"&gt;return&lt;/span&gt; lastName_
+ &lt;span style="color: maroon"&gt;", "&lt;/span&gt; + firstName_; } }&amp;nbsp;&lt;/pre&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&lt;em&gt;49. Use an Organization Name for the Root Namespace, and Narrow by Project, Product
or Group&lt;/em&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: blue"&gt;namespace&lt;/span&gt; Company.Group.Project{ &lt;span style="color: green"&gt;//
...&lt;/span&gt; }&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
This book is an extremely quick read, but well worth the price. It comes in handy
as an excellent reference manual!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=084dadee-8059-4812-817c-54b2084537b6" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=3f39d177-9d3b-4499-a56d-f3317528f449</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,3f39d177-9d3b-4499-a56d-f3317528f449.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <blockquote>
          <p>
"The observer pattern defines a one-to-many dependency between objects so that when
one object changes state, all of its dependents are notified and updated automatically."
- Head First Design Patterns
</p>
        </blockquote>
        <p>
What this means is that if you have objects that are interested in changes in another
object, you allow the "observers" to register or subscribe to the subject. In the
example provided, my wife and mother in law want to be notified whenever i look at
cute girls. Each time i look at a cute girl they should be notified and then they
can take whatever action they want.
</p>
        <p>
Typically, you would push or pull the data from the subject (that's me), to the observers
(that's my wife and her mom). Mo (that's me) contains an internal list of relatives
that want to know what he's up to. Anytime one of his relatives wants to check in
on him, the add themselves to Mo's interal list. If they're no longer interested,
they can remove themselves for the internal list.
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span> Mo( <span style="color: rgb(43, 145, 175);">IList</span>&lt; <span style="color: rgb(43, 145, 175);">IObserver</span> &gt;
concernedRelatives ) { _concernedRelatives = concernedRelatives; LookAtCuteGirl += <span style="color: rgb(0, 0, 255);">delegate</span> {
OnLookedAtCuteGirl( ); }; } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">event</span><span style="color: rgb(43, 145, 175);">EventHandler</span> LookAtCuteGirl; <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">void</span> Add( <span style="color: rgb(43, 145, 175);">IObserver</span> observer
) { _concernedRelatives.Add( observer ); } <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">void</span> Remove( <span style="color: rgb(43, 145, 175);">IObserver</span> observer
) { _concernedRelatives.Remove( observer ); } <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(43, 145, 175);">IList</span>&lt; <span style="color: rgb(43, 145, 175);">IObserver</span> &gt;
_concernedRelatives; <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 255);">void</span> OnLookedAtCuteGirl(
) { <span style="color: rgb(0, 0, 255);">foreach</span> ( <span style="color: rgb(43, 145, 175);">IObserver</span> relative <span style="color: rgb(0, 0, 255);">in</span> _concernedRelatives
) { relative.Update( ); } }</pre>
        <p>
Let's say my wife is concerned and wants to check up on me, here's how she would do
it.
</p>
        <pre class="code">
          <span style="color: rgb(0, 0, 255);">public</span> MosWife( <span style="color: rgb(43, 145, 175);">ISubject</span> husband
) { _husband = husband; _husband.Add( <span style="color: rgb(0, 0, 255);">this</span> );
} <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 255);">void</span> Update(
) { <span style="color: rgb(43, 145, 175);">Console</span>.Out.WriteLine( <span style="color: rgb(163, 21, 21);">"Why
is my husband looking at cute girls?"</span> ); } <span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(43, 145, 175);">ISubject</span> _husband; </pre>
        <p>
She's decided to always add her self to my internal list to see what I'm doing. If
I should happen to check out a cute girl, she will be immediately notified. Lucky
for me, my wife is pretty laid back, and asks herself "Why is my husband looking at
cute girls?"...
</p>
        <p>
Hopefully, this helps to demonstrate the observer pattern. I realize that it is rather
contrived example, and the source could could be refactored. But hopefully it's clear.
</p>
        <p>
For a better explanation, you should read...
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/1170FCGHCFL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>Head First Design Patterns (Head First)</b>
                  <br />
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596007124%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596007124%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
P.S. My wife does not check up on me, she's awesome!
</p>
        <a href="http://mokhan.ca/Blog/content/binary/DesignPatterns.Observer.zip">DesignPatterns.Observer.zip
(4.01 KB)</a>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=3f39d177-9d3b-4499-a56d-f3317528f449" />
      </body>
      <title>The Observer Pattern</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,3f39d177-9d3b-4499-a56d-f3317528f449.aspx</guid>
      <link>http://mokhan.ca/blog/2007/07/06/The+Observer+Pattern.aspx</link>
      <pubDate>Fri, 06 Jul 2007 15:14:45 GMT</pubDate>
      <description>&lt;blockquote&gt; 
&lt;p&gt;
"The observer pattern defines a one-to-many dependency between objects so that when
one object changes state, all of its dependents are notified and updated automatically."
- Head First Design Patterns
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
What this means is that if you have objects that are interested in changes in another
object, you allow the "observers" to register or subscribe to the subject. In the
example provided, my wife and mother in law want to be notified whenever i look at
cute girls. Each time i look at a cute girl they should be notified and then they
can take whatever action they want.
&lt;/p&gt;
&lt;p&gt;
Typically, you would push or pull the data from the subject (that's me), to the observers
(that's my wife and her mom). Mo (that's me) contains an internal list of relatives
that want to know what he's up to. Anytime one of his relatives wants to check in
on him, the add themselves to Mo's interal list. If they're no longer interested,
they can remove themselves for the internal list.
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Mo( &lt;span style="color: rgb(43, 145, 175);"&gt;IList&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;IObserver&lt;/span&gt; &amp;gt;
concernedRelatives ) { _concernedRelatives = concernedRelatives; LookAtCuteGirl += &lt;span style="color: rgb(0, 0, 255);"&gt;delegate&lt;/span&gt; {
OnLookedAtCuteGirl( ); }; } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;event&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;EventHandler&lt;/span&gt; LookAtCuteGirl; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Add( &lt;span style="color: rgb(43, 145, 175);"&gt;IObserver&lt;/span&gt; observer
) { _concernedRelatives.Add( observer ); } &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Remove( &lt;span style="color: rgb(43, 145, 175);"&gt;IObserver&lt;/span&gt; observer
) { _concernedRelatives.Remove( observer ); } &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IList&lt;/span&gt;&amp;lt; &lt;span style="color: rgb(43, 145, 175);"&gt;IObserver&lt;/span&gt; &amp;gt;
_concernedRelatives; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; OnLookedAtCuteGirl(
) { &lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; ( &lt;span style="color: rgb(43, 145, 175);"&gt;IObserver&lt;/span&gt; relative &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; _concernedRelatives
) { relative.Update( ); } }&lt;/pre&gt;
&lt;p&gt;
Let's say my wife is concerned and wants to check up on me, here's how she would do
it.
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; MosWife( &lt;span style="color: rgb(43, 145, 175);"&gt;ISubject&lt;/span&gt; husband
) { _husband = husband; _husband.Add( &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt; );
} &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Update(
) { &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.Out.WriteLine( &lt;span style="color: rgb(163, 21, 21);"&gt;"Why
is my husband looking at cute girls?"&lt;/span&gt; ); } &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ISubject&lt;/span&gt; _husband; &lt;/pre&gt;
&lt;p&gt;
She's decided to always add her self to my internal list to see what I'm doing. If
I should happen to check out a cute girl, she will be immediately notified. Lucky
for me, my wife is pretty laid back, and asks herself "Why is my husband looking at
cute girls?"...
&lt;/p&gt;
&lt;p&gt;
Hopefully, this helps to demonstrate the observer pattern. I realize that it is rather
contrived example, and the source could could be refactored. But hopefully it's clear.
&lt;/p&gt;
&lt;p&gt;
For a better explanation, you should read...
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/1170FCGHCFL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;Head First Design Patterns (Head First)&lt;/b&gt;
&lt;br&gt;
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596007124%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596007124%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
P.S. My wife does not check up on me, she's awesome!
&lt;/p&gt;
&lt;a href="http://mokhan.ca/Blog/content/binary/DesignPatterns.Observer.zip"&gt;DesignPatterns.Observer.zip
(4.01 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=3f39d177-9d3b-4499-a56d-f3317528f449" /&gt;</description>
      <category>Books</category>
      <category>CSharp</category>
      <category>Design Patterns</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=5acc438c-7589-438b-b0fc-6d56eb211b44</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,5acc438c-7589-438b-b0fc-6d56eb211b44.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
HTTP is used for so many different reasons. While working in the wold of point of
sale terminals, I spent some time sending raw HTTP packets and parsing them in C.
Lot's of fun!
</p>
        <p>
Here's a quick little exercise on playing with HTTP, that i found in "Microsoft .NET
Framework 2.0 Web-Based Client Development"
</p>
        <p>
1. Open up a command prompt: Start-&gt;Run-&gt;cmd 
</p>
        <p>
2. type "telnet", and press enter
</p>
        <p>
3. type "o mokhan.ca 80"
</p>
        <p>
4. type 
</p>
        <p>
"GET / HTTP/1.1 
</p>
        <p>
Host: mokhan.ca"
</p>
        <p>
Then press enter twice
</p>
        <p>
But do it quickly, before my server closes the connection due to a timeout!
</p>
        <p>
 
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/11RBAARA7DL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>MCTS Self-Paced Training Kit (Exam 70-528): Microsoft .NET Framework 2.0 Web-Based
Client Development (Pro Certification)</b>
                  <br />
by Glenn Johnson, Tony Northrup<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0735623341%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0735623341%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=5acc438c-7589-438b-b0fc-6d56eb211b44" />
      </body>
      <title>Understanding HTTP</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,5acc438c-7589-438b-b0fc-6d56eb211b44.aspx</guid>
      <link>http://mokhan.ca/blog/2007/07/02/Understanding+HTTP.aspx</link>
      <pubDate>Mon, 02 Jul 2007 23:27:51 GMT</pubDate>
      <description>&lt;p&gt;
HTTP is used for so many different reasons. While working in the wold of point of
sale terminals, I spent some time sending raw HTTP packets and parsing them in C.
Lot's of fun!
&lt;/p&gt;
&lt;p&gt;
Here's a quick little exercise on playing with HTTP, that i found in "Microsoft .NET
Framework 2.0 Web-Based Client Development"
&lt;/p&gt;
&lt;p&gt;
1. Open up a command prompt: Start-&amp;gt;Run-&amp;gt;cmd 
&lt;/p&gt;
&lt;p&gt;
2. type "telnet", and press enter
&lt;/p&gt;
&lt;p&gt;
3. type "o&amp;nbsp;mokhan.ca 80"
&lt;/p&gt;
&lt;p&gt;
4. type 
&lt;/p&gt;
&lt;p&gt;
"GET / HTTP/1.1 
&lt;/p&gt;
&lt;p&gt;
Host: mokhan.ca"
&lt;/p&gt;
&lt;p&gt;
Then press enter twice
&lt;/p&gt;
&lt;p&gt;
But do it quickly, before my server closes the connection due to a timeout!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/11RBAARA7DL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;MCTS Self-Paced Training Kit (Exam 70-528): Microsoft .NET Framework 2.0 Web-Based
Client Development (Pro Certification)&lt;/b&gt;
&lt;br&gt;
by Glenn Johnson, Tony Northrup&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0735623341%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0735623341%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=5acc438c-7589-438b-b0fc-6d56eb211b44" /&gt;</description>
      <category>ASP NET</category>
      <category>Books</category>
    </item>
  </channel>
</rss>