<?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</title>
	<atom:link href="http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Fri, 17 May 2013 09:02:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Mark Nijhof</title>
		<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/#comment-1731</link>
		<dc:creator>Mark Nijhof</dc:creator>
		<pubDate>Wed, 08 Jul 2009 19:39:18 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/06/refactoring-challenge.aspx#comment-1731</guid>
		<description>Hi Jimmy,

This is what I came up with: http://pastie.org/539064

Let me know what you think of it.

-Mark</description>
		<content:encoded><![CDATA[<p>Hi Jimmy,</p>
<p>This is what I came up with: <a href="http://pastie.org/539064" rel="nofollow">http://pastie.org/539064</a></p>
<p>Let me know what you think of it.</p>
<p>-Mark</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank Quednau</title>
		<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/#comment-1730</link>
		<dc:creator>Frank Quednau</dc:creator>
		<pubDate>Tue, 07 Jul 2009 19:56:47 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/06/refactoring-challenge.aspx#comment-1730</guid>
		<description>There may be some of what Fowler called &quot;Inappropriate Intimacy&quot; going on with the context. Maybe your context could help you more if you could ask it better questions...apart from the profileconfiguration stuff all booleans are answerable by the context. E.g. if you have something in cache, or destinationvalue is not null what mappedObject becomes is fully answerable by the context. Then you may get something like

mappedObject = context.TryGetMappedObject(ctx=&gt;mapper.CreateObject(ctx.DestinationType))

The lambda being a Func that gets called when the context could not resolve the mappedObject. The context can use the lambda&#039;s result to add it to its cache if it so requires (answerable by context).

my 5 cent :)</description>
		<content:encoded><![CDATA[<p>There may be some of what Fowler called &#8220;Inappropriate Intimacy&#8221; going on with the context. Maybe your context could help you more if you could ask it better questions&#8230;apart from the profileconfiguration stuff all booleans are answerable by the context. E.g. if you have something in cache, or destinationvalue is not null what mappedObject becomes is fully answerable by the context. Then you may get something like</p>
<p>mappedObject = context.TryGetMappedObject(ctx=>mapper.CreateObject(ctx.DestinationType))</p>
<p>The lambda being a Func that gets called when the context could not resolve the mappedObject. The context can use the lambda&#8217;s result to add it to its cache if it so requires (answerable by context).</p>
<p>my 5 cent <img src='http://lostechies.com/jimmybogard/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Martin</title>
		<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/#comment-1729</link>
		<dc:creator>Chris Martin</dc:creator>
		<pubDate>Tue, 07 Jul 2009 15:40:55 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/06/refactoring-challenge.aspx#comment-1729</guid>
		<description>public object Map(ResolutionContext context, IMappingEngineRunner mapper)
{
    object mappedObject = GetMappedObject(context, mapper);

    TypeMap map = context.TypeMap;

    map.BeforeMap(context.SourceValue, mappedObject);
    map.AfterMap(context.SourceValue, mappedObject);

    return mappedObject;
}

private object GetMappedObject(ResolutionContext context, IMappingEngineRunner mapper)
{
    TypeMap map = context.TypeMap;
    IConfigurationProvider configurationProvider = mapper.ConfigurationProvider;
    var profileConfiguration = configurationProvider.GetProfileConfiguration(map.Profile);
    
    if (map.CustomMapper != null)
    {
        return map.CustomMapper(context);
    }

    if (context.DestinationValue == null &amp;&amp; context.InstanceCache.ContainsKey(context))
    {
        return context.InstanceCache[context];
    }

    if (context.SourceValue != null &#124;&#124; !profileConfiguration.MapNullSourceValuesAsNull)
    {
        object mappedObject = context.DestinationValue ?? mapper.CreateObject(context.DestinationType);

        context.InstanceCache.Add(context, mappedObject);

        map.GetPropertyMaps().ToList().ForEach(pm =&gt; MapPropertyValue(context, mapper, mappedObject, pm));
    }

    return null;
}

http://pastebin.com/m4cb8f96c
^ if unreadable.</description>
		<content:encoded><![CDATA[<p>public object Map(ResolutionContext context, IMappingEngineRunner mapper)<br />
{<br />
    object mappedObject = GetMappedObject(context, mapper);</p>
<p>    TypeMap map = context.TypeMap;</p>
<p>    map.BeforeMap(context.SourceValue, mappedObject);<br />
    map.AfterMap(context.SourceValue, mappedObject);</p>
<p>    return mappedObject;<br />
}</p>
<p>private object GetMappedObject(ResolutionContext context, IMappingEngineRunner mapper)<br />
{<br />
    TypeMap map = context.TypeMap;<br />
    IConfigurationProvider configurationProvider = mapper.ConfigurationProvider;<br />
    var profileConfiguration = configurationProvider.GetProfileConfiguration(map.Profile);</p>
<p>    if (map.CustomMapper != null)<br />
    {<br />
        return map.CustomMapper(context);<br />
    }</p>
<p>    if (context.DestinationValue == null &#038;&#038; context.InstanceCache.ContainsKey(context))<br />
    {<br />
        return context.InstanceCache[context];<br />
    }</p>
<p>    if (context.SourceValue != null || !profileConfiguration.MapNullSourceValuesAsNull)<br />
    {<br />
        object mappedObject = context.DestinationValue ?? mapper.CreateObject(context.DestinationType);</p>
<p>        context.InstanceCache.Add(context, mappedObject);</p>
<p>        map.GetPropertyMaps().ToList().ForEach(pm => MapPropertyValue(context, mapper, mappedObject, pm));<br />
    }</p>
<p>    return null;<br />
}</p>
<p><a href="http://pastebin.com/m4cb8f96c" rel="nofollow">http://pastebin.com/m4cb8f96c</a><br />
^ if unreadable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ollie Riches</title>
		<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/#comment-1728</link>
		<dc:creator>Ollie Riches</dc:creator>
		<pubDate>Tue, 07 Jul 2009 13:53:06 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/06/refactoring-challenge.aspx#comment-1728</guid>
		<description>To many If statements and null checking IMO.

I would try and address this first...</description>
		<content:encoded><![CDATA[<p>To many If statements and null checking IMO.</p>
<p>I would try and address this first&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/#comment-1727</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Tue, 07 Jul 2009 13:00:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/06/refactoring-challenge.aspx#comment-1727</guid>
		<description>@Thomas

Yes, not posting the tests was a bad idea.  I think I&#039;m also running into the issue where all my tests are black-box integration tests.  With the design more locked down, I think it&#039;s time to get unit tests in place.</description>
		<content:encoded><![CDATA[<p>@Thomas</p>
<p>Yes, not posting the tests was a bad idea.  I think I&#8217;m also running into the issue where all my tests are black-box integration tests.  With the design more locked down, I think it&#8217;s time to get unit tests in place.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Eyde</title>
		<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/#comment-1726</link>
		<dc:creator>Thomas Eyde</dc:creator>
		<pubDate>Tue, 07 Jul 2009 12:46:01 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/06/refactoring-challenge.aspx#comment-1726</guid>
		<description>It&#039;s hard to know what to do without specs or tests. Among other things, I see BeforeMap() happens sometimes, but not always. Is that intentional, or is it a bug?</description>
		<content:encoded><![CDATA[<p>It&#8217;s hard to know what to do without specs or tests. Among other things, I see BeforeMap() happens sometimes, but not always. Is that intentional, or is it a bug?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/#comment-1725</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Tue, 07 Jul 2009 12:36:09 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/06/refactoring-challenge.aspx#comment-1725</guid>
		<description>@colinjack

You know, that&#039;s how the code looked at first, multiple exit points.  Flattening seems to be key here....</description>
		<content:encoded><![CDATA[<p>@colinjack</p>
<p>You know, that&#8217;s how the code looked at first, multiple exit points.  Flattening seems to be key here&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/#comment-1724</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Tue, 07 Jul 2009 12:33:36 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/06/refactoring-challenge.aspx#comment-1724</guid>
		<description>@Rob

Yeah, there&#039;s some of that going around.  I don&#039;t that will fix the levels of nested IFs, however.

@Neil

I do like that, I think it brings me one step closer to Chain of Responsibility.</description>
		<content:encoded><![CDATA[<p>@Rob</p>
<p>Yeah, there&#8217;s some of that going around.  I don&#8217;t that will fix the levels of nested IFs, however.</p>
<p>@Neil</p>
<p>I do like that, I think it brings me one step closer to Chain of Responsibility.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fedde Jager</title>
		<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/#comment-1723</link>
		<dc:creator>Fedde Jager</dc:creator>
		<pubDate>Tue, 07 Jul 2009 12:19:37 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/06/refactoring-challenge.aspx#comment-1723</guid>
		<description>Allthough already mentioned..

I would solve it with a by implementing a Chain of Responsibility pattern. Worked out very well for me when I had a very similar issue a few weeks ago.
</description>
		<content:encoded><![CDATA[<p>Allthough already mentioned..</p>
<p>I would solve it with a by implementing a Chain of Responsibility pattern. Worked out very well for me when I had a very similar issue a few weeks ago.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pat</title>
		<link>http://lostechies.com/jimmybogard/2009/07/07/refactoring-challenge/#comment-1722</link>
		<dc:creator>Pat</dc:creator>
		<pubDate>Tue, 07 Jul 2009 11:52:23 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/07/06/refactoring-challenge.aspx#comment-1722</guid>
		<description>Well/mmm,

The bottom line, does it work?  Do you have unit tests w/ coverage?

Nested if statements like the above is a classic case where it falls in the &quot;bah&quot; or &quot;mmm&quot;...  let&#039;s tackle things that are more pressing.  

Also, it&#039;s not that &quot;very, very long&quot; like you say, it fits on one page, and there&#039;s only two &quot;top level if&quot;.  Maybe adding comments would suffice for now.

no change: Don&#039;t add code and/or complexity if the current solution works.

change: On the other hand, if you find the need to add comments then, yeah, time to refactor!

mappedObject = tryMethod1(..)

if (mappedObject != null)
   mappedObject = tryMethod2(..)

if (mappedObject != null)
   mappedObject = tryMethod3(..)

return mappedObject;</description>
		<content:encoded><![CDATA[<p>Well/mmm,</p>
<p>The bottom line, does it work?  Do you have unit tests w/ coverage?</p>
<p>Nested if statements like the above is a classic case where it falls in the &#8220;bah&#8221; or &#8220;mmm&#8221;&#8230;  let&#8217;s tackle things that are more pressing.  </p>
<p>Also, it&#8217;s not that &#8220;very, very long&#8221; like you say, it fits on one page, and there&#8217;s only two &#8220;top level if&#8221;.  Maybe adding comments would suffice for now.</p>
<p>no change: Don&#8217;t add code and/or complexity if the current solution works.</p>
<p>change: On the other hand, if you find the need to add comments then, yeah, time to refactor!</p>
<p>mappedObject = tryMethod1(..)</p>
<p>if (mappedObject != null)<br />
   mappedObject = tryMethod2(..)</p>
<p>if (mappedObject != null)<br />
   mappedObject = tryMethod3(..)</p>
<p>return mappedObject;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
