<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Refactoring challenge Part 1 &#8211; Examination</title>
	<atom:link href="http://lostechies.com/jimmybogard/2009/07/08/refactoring-challenge-part-1-examination/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2009/07/08/refactoring-challenge-part-1-examination/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Thu, 23 May 2013 23:40:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: freddy</title>
		<link>http://lostechies.com/jimmybogard/2009/07/08/refactoring-challenge-part-1-examination/#comment-1737</link>
		<dc:creator>freddy</dc:creator>
		<pubDate>Wed, 08 Jul 2009 23:34:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/07/refactoring-challenge-part-1-examination.aspx#comment-1737</guid>
		<description>Maybe something along the lines:

public object Map(ResolutionContext context, IMappingEngineRunner mapper)
{
    MappingSession mapping = context.StartMappingObject(mapper);
    foreach (PropertyMap propertyMap in mapping.PropertiesNeedingToBeMapped)
    {
        MapPropertyValue(context, mapper, mapping.MappedObject, propertyMap);
    }
    context.EndMapping(mapping);
    return mapping.MappedObject;
}

inside StartMappingObject, u could have something like:

return TypeMap.GetMappedObject(this, DefaultMapper);

inside GetMappedObject:

if ( CustomMapper != null )
{
    BeforeMap(context.SourceValue, null);
    mappedObject = CustomMapper(context);
}
else
{
   var mappedInfo = defaultMapper(mapper,context);
   mappedObject = mappedInfo.MappedObject;
   if( ! mappedInfo.IsCached )
   {
       BeforeMap(context.SourceValue,mappedObject);
   }
}
return mappedObject;

That was just a quick approach, but I really dunno what that code is supposed to be doing. I don&#039;t get why BeforeMap is called before at one time and after at the other, if u could always call it after, u might want to move that into context instead. If not u could still move the BeforeMap outside the if, and u only get a simple if/else. Also in that case, u can refactor the above to avoid passing in the DefaultMapper, by just calling one or the other right from context (which seems hard know because of the placing of the BeforeMap). 

I hope that helps and that I didn&#039;t say a bunch of senseless stuff for the scenario :) </description>
		<content:encoded><![CDATA[<p>Maybe something along the lines:</p>
<p>public object Map(ResolutionContext context, IMappingEngineRunner mapper)<br />
{<br />
    MappingSession mapping = context.StartMappingObject(mapper);<br />
    foreach (PropertyMap propertyMap in mapping.PropertiesNeedingToBeMapped)<br />
    {<br />
        MapPropertyValue(context, mapper, mapping.MappedObject, propertyMap);<br />
    }<br />
    context.EndMapping(mapping);<br />
    return mapping.MappedObject;<br />
}</p>
<p>inside StartMappingObject, u could have something like:</p>
<p>return TypeMap.GetMappedObject(this, DefaultMapper);</p>
<p>inside GetMappedObject:</p>
<p>if ( CustomMapper != null )<br />
{<br />
    BeforeMap(context.SourceValue, null);<br />
    mappedObject = CustomMapper(context);<br />
}<br />
else<br />
{<br />
   var mappedInfo = defaultMapper(mapper,context);<br />
   mappedObject = mappedInfo.MappedObject;<br />
   if( ! mappedInfo.IsCached )<br />
   {<br />
       BeforeMap(context.SourceValue,mappedObject);<br />
   }<br />
}<br />
return mappedObject;</p>
<p>That was just a quick approach, but I really dunno what that code is supposed to be doing. I don&#8217;t get why BeforeMap is called before at one time and after at the other, if u could always call it after, u might want to move that into context instead. If not u could still move the BeforeMap outside the if, and u only get a simple if/else. Also in that case, u can refactor the above to avoid passing in the DefaultMapper, by just calling one or the other right from context (which seems hard know because of the placing of the BeforeMap). </p>
<p>I hope that helps and that I didn&#8217;t say a bunch of senseless stuff for the scenario <img src='http://lostechies.com/jimmybogard/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay</title>
		<link>http://lostechies.com/jimmybogard/2009/07/08/refactoring-challenge-part-1-examination/#comment-1736</link>
		<dc:creator>Jay</dc:creator>
		<pubDate>Wed, 08 Jul 2009 16:29:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/07/refactoring-challenge-part-1-examination.aspx#comment-1736</guid>
		<description>I guess my point was incremental design vs designing it right the first time.  I agree that I don&#039;t think it is really possible to design it right the first time.  However, designing code (IMO) should be part of the small incremental steps of coding.  Using TDD to help you decide what your design should be so that one can see code smells and be able to avoid the rework one would have after the fact.

My guess is that we could have a long discussion on what exactly is rework and refactoring.  I think that&#039;s probably suited for another discussion.  I&#039;d rather concentrate on the solution here and improving the process so it doesn&#039;t peek it&#039;s ugly head again because I have written my share of code smells too! :)</description>
		<content:encoded><![CDATA[<p>I guess my point was incremental design vs designing it right the first time.  I agree that I don&#8217;t think it is really possible to design it right the first time.  However, designing code (IMO) should be part of the small incremental steps of coding.  Using TDD to help you decide what your design should be so that one can see code smells and be able to avoid the rework one would have after the fact.</p>
<p>My guess is that we could have a long discussion on what exactly is rework and refactoring.  I think that&#8217;s probably suited for another discussion.  I&#8217;d rather concentrate on the solution here and improving the process so it doesn&#8217;t peek it&#8217;s ugly head again because I have written my share of code smells too! <img src='http://lostechies.com/jimmybogard/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2009/07/08/refactoring-challenge-part-1-examination/#comment-1735</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Wed, 08 Jul 2009 14:26:25 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/07/refactoring-challenge-part-1-examination.aspx#comment-1735</guid>
		<description>@Jay

One thing to keep in mind is that code changes over time, and it&#039;s not always feasible to design it &quot;right&quot; the first time.  The first time around, I only had one scenario.  Tests would have shown me design issues, but only by looking at multiple tests, and the different responsibilities tested.

This specific code has grown quite gradually over time, so I don&#039;t really feel too bad about it getting &quot;bad&quot;.  That&#039;s the whole point of code smells, to recognize when things need to change at the point in time it needs to change, but not before.</description>
		<content:encoded><![CDATA[<p>@Jay</p>
<p>One thing to keep in mind is that code changes over time, and it&#8217;s not always feasible to design it &#8220;right&#8221; the first time.  The first time around, I only had one scenario.  Tests would have shown me design issues, but only by looking at multiple tests, and the different responsibilities tested.</p>
<p>This specific code has grown quite gradually over time, so I don&#8217;t really feel too bad about it getting &#8220;bad&#8221;.  That&#8217;s the whole point of code smells, to recognize when things need to change at the point in time it needs to change, but not before.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay</title>
		<link>http://lostechies.com/jimmybogard/2009/07/08/refactoring-challenge-part-1-examination/#comment-1734</link>
		<dc:creator>Jay</dc:creator>
		<pubDate>Wed, 08 Jul 2009 14:07:02 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/07/refactoring-challenge-part-1-examination.aspx#comment-1734</guid>
		<description>So why not do it right the first time (i.e. create your unit tests first and design it incramentally, etc)?  This would have avoided all the rework and lost productivity that has occurred.

None the less, for me and I&#039;m sure everyone else, I am grateful that you did it this way so we can all learn how to code much better! 

Thanks!</description>
		<content:encoded><![CDATA[<p>So why not do it right the first time (i.e. create your unit tests first and design it incramentally, etc)?  This would have avoided all the rework and lost productivity that has occurred.</p>
<p>None the less, for me and I&#8217;m sure everyone else, I am grateful that you did it this way so we can all learn how to code much better! </p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl</title>
		<link>http://lostechies.com/jimmybogard/2009/07/08/refactoring-challenge-part-1-examination/#comment-1733</link>
		<dc:creator>Karl</dc:creator>
		<pubDate>Wed, 08 Jul 2009 06:18:14 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/07/refactoring-challenge-part-1-examination.aspx#comment-1733</guid>
		<description>There is also a Law of Demeter violiation in context.TypeMap.CustomMapper and context.InstanceCache.ContainsKey.
This violation will automatically go away if you move more of the logic into the Resolutioncontext as you pointed out above (Feature Envy).</description>
		<content:encoded><![CDATA[<p>There is also a Law of Demeter violiation in context.TypeMap.CustomMapper and context.InstanceCache.ContainsKey.<br />
This violation will automatically go away if you move more of the logic into the Resolutioncontext as you pointed out above (Feature Envy).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Doolittle</title>
		<link>http://lostechies.com/jimmybogard/2009/07/08/refactoring-challenge-part-1-examination/#comment-1732</link>
		<dc:creator>Jeff Doolittle</dc:creator>
		<pubDate>Wed, 08 Jul 2009 06:00:55 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/07/refactoring-challenge-part-1-examination.aspx#comment-1732</guid>
		<description>Thanks for being willing to humbly post ugly code for the common good!  While I&#039;m interested in seeing the refactoring progress, I&#039;d also be interested to see how this may have turned out if built using TDD and emerging design principles.</description>
		<content:encoded><![CDATA[<p>Thanks for being willing to humbly post ugly code for the common good!  While I&#8217;m interested in seeing the refactoring progress, I&#8217;d also be interested to see how this may have turned out if built using TDD and emerging design principles.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
