<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4155214625341815850</id><updated>2012-01-10T01:31:57.375-08:00</updated><title type='text'>Agile Mind Tricks</title><subtitle type='html'>A blog about Agile/XP, Patterns, Test Driven Development, Refactoring and Domain Driven Design.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-6208896364579240748</id><published>2008-06-10T14:37:00.000-07:00</published><updated>2008-06-10T14:38:12.904-07:00</updated><title type='text'>High code coverage + low cyclomatic complexity =  quality code.</title><content type='html'>&lt;p class="MsoNormal"&gt;I have often heard and agree with the statement that 100% code coverage does not guaranty quality code. However, if you also monitor cyclomatic complexity of your code you will greatly increase the probability that it is problem free. If any method does not have 100% coverage or has cyclomatic complexity greater that 7 it should be suspect. The tool that I currently use for cyclomatic complexity is Code Monitor www.campwoodsw.com/sourcemonitor.html&lt;/p&gt;  &lt;hints id="hah_hints"&gt;&lt;/hints&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-6208896364579240748?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/6208896364579240748/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=6208896364579240748' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/6208896364579240748'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/6208896364579240748'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2008/06/high-code-coverage-low-cyclomatic.html' title='High code coverage + low cyclomatic complexity =  quality code.'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-3605361729164819425</id><published>2008-01-11T14:04:00.000-08:00</published><updated>2008-01-11T14:05:18.662-08:00</updated><title type='text'>Debugger Driven Development</title><content type='html'>I have just discovered a new way of doing TDD and I am calling it Debugger Driven Development.&lt;br /&gt;&lt;br /&gt;This is how you do Debugger Driven Development.&lt;br /&gt;1) Write a test which calls some method that does some complex calculation.&lt;br /&gt;2) Add an assert statement with a null expected value.&lt;br /&gt;3) Run the test in the debugger get the actual value returned by the method and use it for the expected value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Debugger Driven Development is just so wrong. It does have some value for regression testing assuming your code is correct but it will cause big problems if it's incorrect. What you should do is always calculate the expected value by hand. That way if the value returned by your program matches your hand calculation their is a high probability that your code is correct. Doing Debugger Driven Development proves nothing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-3605361729164819425?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/3605361729164819425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=3605361729164819425' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/3605361729164819425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/3605361729164819425'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2008/01/debugger-driven-development.html' title='Debugger Driven Development'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-5102339548303456801</id><published>2008-01-11T13:23:00.001-08:00</published><updated>2008-01-11T13:39:05.046-08:00</updated><title type='text'>Encapsulate complicated or generic code</title><content type='html'>Whenever you come across code that is more complex or generic than it needs to be try to refactor it. However it may not be possible to do this in some cases. When that happens just wrap the complex code with your own class that has the interface that you wished you had to work with.&lt;br /&gt;&lt;br /&gt;Here is an example&lt;br /&gt;&lt;br /&gt;The following code calls gateway.GetProducts(criteria) to return an array of products. Notice that most of the code below is just used to set up the criteria object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=";font-family:arial;font-size:85%;"  &gt;ICriterion salesDateCriterion = new SalesDateCriterion(newstring[]{uploadDate.ToString()},&lt;br /&gt;                  OperationEnum.Equal);&lt;br /&gt;ICriterion prodLineIdCriterion = new ProdLineIdCriterion(new string[]&lt;br /&gt;                  {productionLineId.ToString()},OperationEnum.Equal);&lt;br /&gt;ICriterion productNoCriterion = new ProductNoCriterion(productNo.ToString(),&lt;br /&gt;                  OperationEnum.Equal);&lt;br /&gt;ICriterion[] criteria = new ICriterion[] {salesDateCriterion, prodLineIdCriterion,              &lt;br /&gt;                  productNoCriterion};&lt;br /&gt;&lt;br /&gt;IProduct[] products = gateway.GetProducts(criteria);&lt;br /&gt;&lt;br /&gt;if (products.Length != 1 || products[0] == null)&lt;br /&gt;              throw new Exception("Product not found");&lt;br /&gt;&lt;br /&gt;return products[0];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For my application I did not need the power that criteria gave me I only needed to find a single product by uploadDate, productionLineId and productNo. So I just wrapped the above code in a method called GetProduct. Now the client code now contains a single line of code that is much easier to understand.&lt;br /&gt;&lt;br /&gt;&lt;span style=";font-family:arial;font-size:85%;"  &gt;public IProduct GetProduct(UploadDate, productionLine,productNo)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the newly created class I also added two similar methods GetVariety and GetOrder.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:arial;"&gt;public IVariety GetVariety(int varietyNo)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;public IOrder GetOrder(DateTime uploadDate, int productionLineId, int productNo)&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-5102339548303456801?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/5102339548303456801/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=5102339548303456801' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/5102339548303456801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/5102339548303456801'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2008/01/encapsulate-complicated-or-generic-code.html' title='Encapsulate complicated or generic code'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-3542677556524274352</id><published>2007-12-05T07:41:00.000-08:00</published><updated>2007-12-05T07:46:26.759-08:00</updated><title type='text'>Microsoft Advertising Ruby On Rails.</title><content type='html'>Today I went to Microsoft’s ASP.Net website and was surprised to find it advertising Ruby On Rails.&lt;br /&gt;&lt;br /&gt;"Experience the latest release of the most productive and powerful development tool and user interface platform on the planet."&lt;br /&gt;&lt;br /&gt;However those guys at Microsoft screwed up the images and download link. The download link pointed to ASP.NET 3.5 instead.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-3542677556524274352?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/3542677556524274352/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=3542677556524274352' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/3542677556524274352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/3542677556524274352'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2007/12/microsoft-advertising-ruby-on-rails.html' title='Microsoft Advertising Ruby On Rails.'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-6903740924150859951</id><published>2007-11-23T07:29:00.000-08:00</published><updated>2007-11-23T07:35:20.948-08:00</updated><title type='text'>IThis, IThat, ITheOther</title><content type='html'>I have seen projects where every class had implemented an interface by default. The interfaces always had the same names as the classes except they were prefixed with an (I). I don't call this good design. The flexibility that an interface gives you has a cost. If an interface is not paying for this cost it should be removed. Only use interfaces when the flexibility is required. It is often difficult to tell in advance where this flexibility is needed so it is usually best to add an interface when the flexibility is required. Also instead of using the (I) prefix I prefer to name the interface by how the client will use the class. So instead of creating and IBook interface for a Book class, I could create a Readable interface instead. Removing the last trace of Hungarian notation from my code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-6903740924150859951?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/6903740924150859951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=6903740924150859951' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/6903740924150859951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/6903740924150859951'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2007/11/ithis-ithat-itheother.html' title='IThis, IThat, ITheOther'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-9192242721797134197</id><published>2007-11-21T10:22:00.001-08:00</published><updated>2007-11-21T10:22:50.799-08:00</updated><title type='text'>Singleton Anti-Pattern</title><content type='html'>The Singleton pattern is probably the most over used design pattern there is. Singletons are the same as global variables and make object collaboration less visible. They violate the Single Responsibility Principle mixing an object with its creation logic. They also create difficult to test code because they bind you to the exact type of the Singleton object and Singletons persist state causing test order to be dependent.&lt;br /&gt;&lt;br /&gt; A Singleton object should be rarely used and when used it should be only used to solve a performance issue or as a last resort when parameter passing becomes very difficult.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-9192242721797134197?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/9192242721797134197/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=9192242721797134197' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/9192242721797134197'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/9192242721797134197'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2007/11/singleton-anti-pattern.html' title='Singleton Anti-Pattern'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-8009410794109523549</id><published>2007-11-08T07:41:00.000-08:00</published><updated>2007-11-08T07:46:10.921-08:00</updated><title type='text'>What makes an excellent developer excellent?</title><content type='html'>Is it his knowledge of C# or Java Syntax? Is it his knowledge of every corner of every obscure framework? I don't think so. It is important to know what is possible in a language or framework but you can always lookup the fine details when you need to.&lt;br /&gt;&lt;br /&gt;This reminds me of a story of when one of Einstein's colleagues asked him for his telephone number one day. Einstein reached for a telephone directory and looked it up. "You don't remember your own number?" the man asked, startled. "No," Einstein answered. "Why should I memorize something I can so easily get from a book?"&lt;br /&gt;&lt;br /&gt;It is the developer’s knowledge of good object oriented design principles and domain modeling that makes a great developer stand out. If you are not strong in these areas it will be very difficult for you to Google them as you go.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-8009410794109523549?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/8009410794109523549/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=8009410794109523549' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/8009410794109523549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/8009410794109523549'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2007/11/what-makes-excellent-developer.html' title='What makes an excellent developer excellent?'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-651728398241218636</id><published>2007-11-06T14:07:00.001-08:00</published><updated>2007-11-06T14:09:49.773-08:00</updated><title type='text'>Replace With Direct Cast</title><content type='html'>An instance of the as operator should always be followed by a check against null.&lt;br /&gt;&lt;br /&gt;Customer customer = obj as Customer;&lt;br /&gt;&lt;br /&gt;if(customer != null){&lt;br /&gt;   customer.Update();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;If you don't want to check against null than refactor to a direct cast.&lt;br /&gt;&lt;br /&gt;(obj as customer).Update;&lt;br /&gt;&lt;br /&gt;If the direct cast fails you will get an InvalidCastException instead of a NullReferenceException which will be easier to diagnose.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-651728398241218636?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/651728398241218636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=651728398241218636' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/651728398241218636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/651728398241218636'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2007/11/replace-with-direct-cast.html' title='Replace With Direct Cast'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-1467598970346998316</id><published>2007-11-05T13:43:00.000-08:00</published><updated>2007-11-05T13:49:39.304-08:00</updated><title type='text'>Remove Unneeded Property</title><content type='html'>If you have a property that looks like the following just remove it. It is not adding any value.&lt;br /&gt;&lt;br /&gt;public string PositionTitle&lt;br /&gt;{&lt;br /&gt;   get&lt;br /&gt;   { &lt;br /&gt;      return this.positionTitle;&lt;br /&gt;   }&lt;br /&gt;   set&lt;br /&gt;   {&lt;br /&gt;      this.positionTitle = value;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Refactoring tools such as Resharper make encapsulating a field simple. So you can always refactor to the property later if you find that you need it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now doesn't the following code look so much nicer?&lt;br /&gt;&lt;br /&gt;public string positionTitle;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-1467598970346998316?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/1467598970346998316/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=1467598970346998316' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/1467598970346998316'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/1467598970346998316'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2007/11/remove-unneeded-property.html' title='Remove Unneeded Property'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-1034507735295654832</id><published>2007-10-24T06:58:00.000-07:00</published><updated>2007-10-24T07:24:45.007-07:00</updated><title type='text'>Replace multidimensional if condition with double dispatch.</title><content type='html'>If you have a series of if conditions that vary in two dimensions it may be possible to replace the conditionals with double dispatch.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;public class passenger&lt;br /&gt;{&lt;br /&gt;public Vehicle vehicle;&lt;br /&gt;public string type;&lt;br /&gt;public void travel()&lt;br /&gt;{&lt;br /&gt;if (vehicle.Type == "Car")&lt;br /&gt;{&lt;br /&gt;if (this.Type = "Rich")&lt;br /&gt;{&lt;br /&gt;RideInLimo();&lt;br /&gt;}&lt;br /&gt;else if (Passenger.Type = "Poor")&lt;br /&gt;{&lt;br /&gt;Drive();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;else if (vehicle.Type = "Airplane")&lt;br /&gt;{&lt;br /&gt;if (this.Type = "Rich")&lt;br /&gt;FlyInPrivateJet();&lt;br /&gt;else if (Passenger.Type = "Poor")&lt;br /&gt;{&lt;br /&gt;FlyCoach();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the above example the first refactoring that I would like to apply is &lt;a href="http://www.refactoring.com/catalog/replaceTypeCodeWithClass.html"&gt;Replace Type Code with Class&lt;/a&gt;. However the way a person travels does not only depend on the type of vehicle he uses but also the type of person they are as well. This problem can be solved by passenger passing itself as a parameter to the vehicle class. Then the vehicle class can use method overloading to create to versions of the travel method for each type of person.&lt;br /&gt;&lt;br /&gt;Here is the refactored code.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:arial;"&gt;public class Passenger&lt;br /&gt;{&lt;br /&gt;public Vehicle vehicle;&lt;br /&gt;public void Travel()&lt;br /&gt;{&lt;br /&gt;vehicle.Travel(this);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Car : vehicle&lt;br /&gt;{&lt;br /&gt;public void Travel(RichPersion Passenger)&lt;br /&gt;{&lt;br /&gt;RideInLimo();&lt;br /&gt;}&lt;br /&gt;public void Travel(PoorPersion Passenger)&lt;br /&gt;{&lt;br /&gt;Drive();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class Plane : vehicle&lt;br /&gt;{&lt;br /&gt;public void Travel(RichPerson Passenger)&lt;br /&gt;{&lt;br /&gt;FlyInPrivateJet();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void Travel(PoorPerson Passenger)&lt;br /&gt;{&lt;br /&gt;FlyCoach();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;One drawback of using this approach is that it violates the Open Close Principle because you will have to add a new version of the travel method on the vehicle object for each new person type that you add to your application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-1034507735295654832?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/1034507735295654832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=1034507735295654832' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/1034507735295654832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/1034507735295654832'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2007/10/replace-multidimensional-if-condition.html' title='Replace multidimensional if condition with double dispatch.'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-2957938090876164104</id><published>2007-10-22T09:06:00.000-07:00</published><updated>2007-10-22T09:07:54.050-07:00</updated><title type='text'>Move Foreign Method to Server Class</title><content type='html'>When I am working with code that is not object oriented I often see a bunch of objects that just contain data and not much behavior. These methods are often passed to helper classes that perform the real work.&lt;br /&gt;&lt;br /&gt;Class MyHelperClass&lt;br /&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;{&lt;br /&gt;   public static void DoSomething(MyObject thing)&lt;br /&gt;   {&lt;br /&gt;            Dothis(thing.This);&lt;br /&gt;            Dothat(thing.That);&lt;br /&gt;            DoTheother(thing.Other):&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Whenever I see static helper functions I look at the parameter list for objects that would be a better home for the function.&lt;br /&gt;&lt;br /&gt;This specific instance of the &lt;a href="http://www.refactoring.com/catalog/moveMethod.html"&gt;Move Method&lt;/a&gt; refactoring is kind of the reverse of the &lt;a href="http://www.refactoring.com/catalog/introduceForeignMethod.html"&gt;Foreign Method&lt;/a&gt; refactoring. So my name for this refactoring is "Move Foreign Method to Server Class"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-2957938090876164104?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/2957938090876164104/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=2957938090876164104' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/2957938090876164104'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/2957938090876164104'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2007/10/move-foreign-method-to-server-class.html' title='Move Foreign Method to Server Class'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-2153769807840493813</id><published>2007-10-19T12:52:00.000-07:00</published><updated>2007-10-19T12:57:04.561-07:00</updated><title type='text'>Fluent Constructors</title><content type='html'>&lt;p&gt;Something in the following code just does not look right to me.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;Employee employee = new  Employee();&lt;br /&gt;employee.EmployeeNumber ="1565407"&lt;br /&gt;employee.Name = "Nick"&lt;br /&gt;employee.LastName = "Markovic"&lt;br /&gt;employee.JobFunction = CreateJobFunction("Tester")&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Employee Constructor just tells me nothing on how to use the object.&lt;br /&gt;&lt;br /&gt;It does not tell which properties are required and which are not.&lt;br /&gt;In this example EmployeeNumber, Name and LastName were all required but JobFunction was not. To make things worse the employee object has about 20 other properties on it. I came across this problem while I was writing unit tests for legacy code and needed to create a simple employee to pass as a parameter. I had to go digging through the internals of employee to determine which fields needed to be set.&lt;br /&gt; However if the creator of this class had crated a constructor that looked something like Employee(number,firstName,LastName). The interface would be much more fluent and would create much easier to understand code. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-2153769807840493813?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/2153769807840493813/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=2153769807840493813' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/2153769807840493813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/2153769807840493813'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2007/10/fluent-constructors.html' title='Fluent Constructors'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4155214625341815850.post-4114251358593697920</id><published>2007-10-19T12:51:00.001-07:00</published><updated>2007-10-19T12:57:45.011-07:00</updated><title type='text'>Strings - The only data type you will ever need.</title><content type='html'>I have seen lots of code that looks like the following&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;Person candidate = CreatePerson()&lt;br /&gt;string hireDate= "02/12/2005"&lt;br /&gt;string departmentId = "12";&lt;br /&gt;HirePerson(person,hireDate,departmentId)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I often see methods that take strings as parameters when they are dealing with values that should be stored in more expressive data types. Usually this happens with values that get pulled out of text boxes on the UI. These parameters start getting pasted all over the place and only end up getting cast to a more specific data type when some special functionality like date comparison is needed.I have also seen this happen with id values. They often get converted back and forth from int to string as they get passed around the application. I guess this code smell is kind of like primitive obsession taken to the extreme.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4155214625341815850-4114251358593697920?l=agilemindtricks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agilemindtricks.blogspot.com/feeds/4114251358593697920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4155214625341815850&amp;postID=4114251358593697920' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/4114251358593697920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4155214625341815850/posts/default/4114251358593697920'/><link rel='alternate' type='text/html' href='http://agilemindtricks.blogspot.com/2007/10/strings-only-data-type-you-will-ever.html' title='Strings - The only data type you will ever need.'/><author><name>Nick Markovic</name><uri>http://www.blogger.com/profile/05656293763086795455</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp2.blogger.com/_kjHGxcQikrA/R4enab7QYyI/AAAAAAAAAAM/lO3zSl6CfFQ/S220/IMG_2646_edited.JPG'/></author><thr:total>2</thr:total></entry></feed>
