<?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 Day 10 : Extract Method</title>
	<atom:link href="http://lostechies.com/seanchambers/2009/08/10/refactoring-day-10-extract-method/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/seanchambers/2009/08/10/refactoring-day-10-extract-method/</link>
	<description>Just another LosTechies site</description>
	<lastBuildDate>Thu, 13 Sep 2012 07:11: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: Gunnar Peipman</title>
		<link>http://lostechies.com/seanchambers/2009/08/10/refactoring-day-10-extract-method/#comment-390</link>
		<dc:creator>Gunnar Peipman</dc:creator>
		<pubDate>Tue, 11 Aug 2009 17:16:08 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2009/08/10/refactoring-day-10-extract-method.aspx#comment-390</guid>
		<description>I agree about unit tests. I just thought that after meeting with sales department discount calculations are not so easy anymore :P</description>
		<content:encoded><![CDATA[<p>I agree about unit tests. I just thought that after meeting with sales department discount calculations are not so easy anymore <img src='http://lostechies.com/seanchambers/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: schambers</title>
		<link>http://lostechies.com/seanchambers/2009/08/10/refactoring-day-10-extract-method/#comment-389</link>
		<dc:creator>schambers</dc:creator>
		<pubDate>Mon, 10 Aug 2009 20:07:10 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2009/08/10/refactoring-day-10-extract-method.aspx#comment-389</guid>
		<description>@Gunnar

Good point on checking for Discounts.Count &gt; 0 and changing that to return 0 instead.

As far as setting the methods to protected for the reason of unit testing, I&#039;m not sure I agree with this. A unit test for this class would excercise the public method CalculateGrandTotal with specific inputs. Granted, Discounts would have to be initialized via a ctor or something along those lines to get different Discounts in there. I digress however, my point is you should not be testing those individual methods, but instead should be treating the public method as a black box. I don&#039;t care how the class accomplishes it&#039;s work, just as long as all code paths are executed for proper coverage.

Testing private methods is a code smell IMO. The whole reason for having them private is because the class knows how to accomplish it&#039;s work. You would simply have several different scenarios for testing CalculateGrandTotal to excercise all paths.</description>
		<content:encoded><![CDATA[<p>@Gunnar</p>
<p>Good point on checking for Discounts.Count > 0 and changing that to return 0 instead.</p>
<p>As far as setting the methods to protected for the reason of unit testing, I&#8217;m not sure I agree with this. A unit test for this class would excercise the public method CalculateGrandTotal with specific inputs. Granted, Discounts would have to be initialized via a ctor or something along those lines to get different Discounts in there. I digress however, my point is you should not be testing those individual methods, but instead should be treating the public method as a black box. I don&#8217;t care how the class accomplishes it&#8217;s work, just as long as all code paths are executed for proper coverage.</p>
<p>Testing private methods is a code smell IMO. The whole reason for having them private is because the class knows how to accomplish it&#8217;s work. You would simply have several different scenarios for testing CalculateGrandTotal to excercise all paths.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gunnar Peipman</title>
		<link>http://lostechies.com/seanchambers/2009/08/10/refactoring-day-10-extract-method/#comment-388</link>
		<dc:creator>Gunnar Peipman</dc:creator>
		<pubDate>Mon, 10 Aug 2009 19:57:13 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2009/08/10/refactoring-day-10-extract-method.aspx#comment-388</guid>
		<description>I can see no point of this if

private decimal CalculateDiscounts(decimal subTotal)
{
    if (Discounts.Count &gt; 0)
    {
        foreach (decimal discount in Discounts)
            subTotal -= discount;
    }
}

But i can see potential danger if Discounts is null. So better write it this way:

private decimal CalculateDiscounts(decimal subTotal)
{
    if (Discounts.Count == null)
        return 0;

    foreach (decimal discount in Discounts)
        subTotal -= discount;
}

Also make these methods at least as protected because one may also want to unit test them.</description>
		<content:encoded><![CDATA[<p>I can see no point of this if</p>
<p>private decimal CalculateDiscounts(decimal subTotal)<br />
{<br />
    if (Discounts.Count > 0)<br />
    {<br />
        foreach (decimal discount in Discounts)<br />
            subTotal -= discount;<br />
    }<br />
}</p>
<p>But i can see potential danger if Discounts is null. So better write it this way:</p>
<p>private decimal CalculateDiscounts(decimal subTotal)<br />
{<br />
    if (Discounts.Count == null)<br />
        return 0;</p>
<p>    foreach (decimal discount in Discounts)<br />
        subTotal -= discount;<br />
}</p>
<p>Also make these methods at least as protected because one may also want to unit test them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Crane</title>
		<link>http://lostechies.com/seanchambers/2009/08/10/refactoring-day-10-extract-method/#comment-387</link>
		<dc:creator>Steve Crane</dc:creator>
		<pubDate>Mon, 10 Aug 2009 14:44:31 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2009/08/10/refactoring-day-10-extract-method.aspx#comment-387</guid>
		<description>It might have been clearer to have the refactored methods simply return the calculated value and call them as

    subTotal -= CalculateDiscounts(subTotal);
    subTotal += CalculateTax(subTotal);

or to have called them CalculateAndDeductDiscounts() and CalculateAndAddTax() if they are doing the addition and deduction too.</description>
		<content:encoded><![CDATA[<p>It might have been clearer to have the refactored methods simply return the calculated value and call them as</p>
<p>    subTotal -= CalculateDiscounts(subTotal);<br />
    subTotal += CalculateTax(subTotal);</p>
<p>or to have called them CalculateAndDeductDiscounts() and CalculateAndAddTax() if they are doing the addition and deduction too.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
