<?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: Prefer Additional Methods Over Additional Overloads</title>
	<atom:link href="http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
	<description></description>
	<lastBuildDate>Sun, 12 Feb 2012 18:54:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
	<item>
		<title>By: Sebastian Schuth</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/comment-page-3/#comment-57897</link>
		<dc:creator>Sebastian Schuth</dc:creator>
		<pubDate>Tue, 29 Jun 2010 11:38:42 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comment-57897</guid>
		<description>&quot;Try to think from the perspective of someone using your code when writing your code&quot; - There is an easy way to do this: write tests first, and you&#039;ll see if using teh api over and over again in different contexts is making sense.</description>
		<content:encoded><![CDATA[<p>&#8220;Try to think from the perspective of someone using your code when writing your code&#8221; &#8211; There is an easy way to do this: write tests first, and you&#8217;ll see if using teh api over and over again in different contexts is making sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Sorensen</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/comment-page-3/#comment-57841</link>
		<dc:creator>Bill Sorensen</dc:creator>
		<pubDate>Thu, 24 Jun 2010 18:05:52 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comment-57841</guid>
		<description>I agree with your refactoring; I think the code smell is the Boolean parameter, though. If your method has a Boolean parameter, it&#039;s probably doing more than one thing (thus violating SRP). Enum parameter types are also potential code smells.</description>
		<content:encoded><![CDATA[<p>I agree with your refactoring; I think the code smell is the Boolean parameter, though. If your method has a Boolean parameter, it&#8217;s probably doing more than one thing (thus violating SRP). Enum parameter types are also potential code smells.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/comment-page-3/#comment-57830</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 22 Jun 2010 13:30:26 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comment-57830</guid>
		<description>&lt;a href=&quot;#comment-57828&quot; rel=&quot;nofollow&quot;&gt;@Henning Anderssen&lt;/a&gt; 
Good point!

I agree wholeheartedly with your reasoning and example.
In fact my next post is going to be on constraining user input through the use of custom parameter classes.

I don&#039;t think what I am talking about in my post and what you are saying here are necessarily mutually exclusive though.  It kind of depends on the situation and what data your storing and how your API is interacted with.  I could easily see a login method that takes in a fullName, but is an additional method instead of an overload.

I agree also that you can store parameters in the class instance, but you will still have to get them in there somehow.  Which can jump move the problem up to overloaded constructors.

Good points though excellent discussion.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57828" rel="nofollow">@Henning Anderssen</a><br />
Good point!</p>
<p>I agree wholeheartedly with your reasoning and example.<br />
In fact my next post is going to be on constraining user input through the use of custom parameter classes.</p>
<p>I don&#8217;t think what I am talking about in my post and what you are saying here are necessarily mutually exclusive though.  It kind of depends on the situation and what data your storing and how your API is interacted with.  I could easily see a login method that takes in a fullName, but is an additional method instead of an overload.</p>
<p>I agree also that you can store parameters in the class instance, but you will still have to get them in there somehow.  Which can jump move the problem up to overloaded constructors.</p>
<p>Good points though excellent discussion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/comment-page-3/#comment-57829</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 22 Jun 2010 13:23:30 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comment-57829</guid>
		<description>&lt;a href=&quot;#comment-57825&quot; rel=&quot;nofollow&quot;&gt;@John Atwood&lt;/a&gt; 
I definitely have to agree with you there John.  Good example.  Yes, if the overload does exactly the same thing and only differs in type, it should be an overload rather than an additional method.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57825" rel="nofollow">@John Atwood</a><br />
I definitely have to agree with you there John.  Good example.  Yes, if the overload does exactly the same thing and only differs in type, it should be an overload rather than an additional method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henning Anderssen</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/comment-page-2/#comment-57828</link>
		<dc:creator>Henning Anderssen</dc:creator>
		<pubDate>Tue, 22 Jun 2010 08:07:22 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comment-57828</guid>
		<description>John,

I don&#039;t necessarily see that as a bad thing.
Consider the following method:
public void DoSomethingWithUser(string firstname, string middlename, string lastname, int age);

When reading that, how do you know which string is which. What if the creator of that method decides to swap the name string. You get no compiletime checks, and the signature is harder to read.
Now, take this method signature instead. It is much easier to read and you know just by reading the signature what it accepts, plus it gives you compiletime checks if you decide to move the parameter.
public void DoSomethingWithUser(Name fullName, int age);


Btw, we&#039;ve all been under the assumption that you have to pass in the parameters into the method. In many cases, you&#039;d want to do that, but sometimes wouldn&#039;t it be better to have the class statefull instead.
Case in point, lets take the Login example. Do you REALLY need to send in the parameters? Can&#039;t you just store the parameters in the class instance instead. That would mean the login method would have no parameters. Nothing beats that ;).
It won&#039;t work all the time in all usecases, but it is something you should consider when you create your api/system.</description>
		<content:encoded><![CDATA[<p>John,</p>
<p>I don&#8217;t necessarily see that as a bad thing.<br />
Consider the following method:<br />
public void DoSomethingWithUser(string firstname, string middlename, string lastname, int age);</p>
<p>When reading that, how do you know which string is which. What if the creator of that method decides to swap the name string. You get no compiletime checks, and the signature is harder to read.<br />
Now, take this method signature instead. It is much easier to read and you know just by reading the signature what it accepts, plus it gives you compiletime checks if you decide to move the parameter.<br />
public void DoSomethingWithUser(Name fullName, int age);</p>
<p>Btw, we&#8217;ve all been under the assumption that you have to pass in the parameters into the method. In many cases, you&#8217;d want to do that, but sometimes wouldn&#8217;t it be better to have the class statefull instead.<br />
Case in point, lets take the Login example. Do you REALLY need to send in the parameters? Can&#8217;t you just store the parameters in the class instance instead. That would mean the login method would have no parameters. Nothing beats that <img src='http://elegantcode.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .<br />
It won&#8217;t work all the time in all usecases, but it is something you should consider when you create your api/system.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerod Houghtelling</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/comment-page-2/#comment-57827</link>
		<dc:creator>Jerod Houghtelling</dc:creator>
		<pubDate>Tue, 22 Jun 2010 03:59:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comment-57827</guid>
		<description>I was skimming through Martin Fowler&#039;s Refactoring book and noticed this quote under &#039;Replace Parameter with Explicit Methods&#039; on page 285.

&quot;The usual case for [Replace Parameter with Explicit Methods] is that you have discrete values of a parameter, test for those values in a conditional, and do different things. The caller has to decide what it wants to do by setting the parameter, so you might as well provide different methods and avoid the conditional. You not only avoid the conditional behavior but also gain compile time checking. Furthermore your interface also is clearer.  With the parameter, any programmer using the method needs not only to look at the methods on the class but also to determine a valid parameter value. The latter is often poorly documented.&quot;

This isn&#039;t directly related to overloaded methods, but I believe that overloaded methods are near equivalent to one method with several conditional parameters.

With .Net 40 and optional parameters, this is taken to the next level of complexity. I guess we&#039;ll just have to see how they will scale and be maintained. 

Wasn&#039;t one of the reasons for optional parameters was to help with the complexity for COM operability?</description>
		<content:encoded><![CDATA[<p>I was skimming through Martin Fowler&#8217;s Refactoring book and noticed this quote under &#8216;Replace Parameter with Explicit Methods&#8217; on page 285.</p>
<p>&#8220;The usual case for [Replace Parameter with Explicit Methods] is that you have discrete values of a parameter, test for those values in a conditional, and do different things. The caller has to decide what it wants to do by setting the parameter, so you might as well provide different methods and avoid the conditional. You not only avoid the conditional behavior but also gain compile time checking. Furthermore your interface also is clearer.  With the parameter, any programmer using the method needs not only to look at the methods on the class but also to determine a valid parameter value. The latter is often poorly documented.&#8221;</p>
<p>This isn&#8217;t directly related to overloaded methods, but I believe that overloaded methods are near equivalent to one method with several conditional parameters.</p>
<p>With .Net 40 and optional parameters, this is taken to the next level of complexity. I guess we&#8217;ll just have to see how they will scale and be maintained. </p>
<p>Wasn&#8217;t one of the reasons for optional parameters was to help with the complexity for COM operability?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Atwood</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/comment-page-2/#comment-57825</link>
		<dc:creator>John Atwood</dc:creator>
		<pubDate>Mon, 21 Jun 2010 21:47:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comment-57825</guid>
		<description>A guideline that I like to follow with overloads is this:

1) Overloaded methods should have exactly the same behavior.
2) Since overloaded methods have the same behavior all methods can be implemented in terms of one of the methods, usually this is the method that takes the most low level parameters.

A good example of this pattern is the System.IO.TextWriter class. All implementations of Write and WriteLine eventually boil down to uses of the Write(char) method.

I would prefer to use the TextWriter as written, rather than a class with umpteen methods like WriteInt32, WriteLong, WriteChar, WriteDouble, etc.</description>
		<content:encoded><![CDATA[<p>A guideline that I like to follow with overloads is this:</p>
<p>1) Overloaded methods should have exactly the same behavior.<br />
2) Since overloaded methods have the same behavior all methods can be implemented in terms of one of the methods, usually this is the method that takes the most low level parameters.</p>
<p>A good example of this pattern is the System.IO.TextWriter class. All implementations of Write and WriteLine eventually boil down to uses of the Write(char) method.</p>
<p>I would prefer to use the TextWriter as written, rather than a class with umpteen methods like WriteInt32, WriteLong, WriteChar, WriteDouble, etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerod Houghtelling</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/comment-page-2/#comment-57824</link>
		<dc:creator>Jerod Houghtelling</dc:creator>
		<pubDate>Mon, 21 Jun 2010 19:18:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comment-57824</guid>
		<description>I&#039;m all in favor of having multiple methods as your public API -- instead of one gigantic set of overloads. If you really want a gigantic overload method there&#039;s no reason why you couldn&#039;t do it as a private method that each of the public methods would call. Yes, it adds more code, but I feel the code is easier to understand by both the public API and the internal class. I feel that by making the overloaded method public you are broadcasting to much information about your specific implementation. The  descriptive method names encapsulate your implementation -- that means you are free to change the back-end it all you want! If you did an overload you _probably_ would have to continually adjust the public API as well when the back-end changes.</description>
		<content:encoded><![CDATA[<p>I&#8217;m all in favor of having multiple methods as your public API &#8212; instead of one gigantic set of overloads. If you really want a gigantic overload method there&#8217;s no reason why you couldn&#8217;t do it as a private method that each of the public methods would call. Yes, it adds more code, but I feel the code is easier to understand by both the public API and the internal class. I feel that by making the overloaded method public you are broadcasting to much information about your specific implementation. The  descriptive method names encapsulate your implementation &#8212; that means you are free to change the back-end it all you want! If you did an overload you _probably_ would have to continually adjust the public API as well when the back-end changes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/comment-page-2/#comment-57823</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 21 Jun 2010 19:16:42 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comment-57823</guid>
		<description>&lt;a href=&quot;#comment-57822&quot; rel=&quot;nofollow&quot;&gt;@Adam dR.&lt;/a&gt; 
Yes Adam, good points.  I also agree with Wanja about the use of enumerations.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57822" rel="nofollow">@Adam dR.</a><br />
Yes Adam, good points.  I also agree with Wanja about the use of enumerations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam dR.</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/comment-page-2/#comment-57822</link>
		<dc:creator>Adam dR.</dc:creator>
		<pubDate>Mon, 21 Jun 2010 19:05:12 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comment-57822</guid>
		<description>&lt;a href=&quot;#comment-57820&quot; rel=&quot;nofollow&quot;&gt;@John Sonmez &lt;/a&gt; 
I completely agree with Wanja on the use of enumerations to help simplify the API and make it more expressive.

I also want to note that I agree with you John, on the trying to make a cleaner API. One thing I am a fan of is the new push for fluent interfaces. (http://msdn.microsoft.com/en-us/magazine/ee291514.aspx) I think in some ways this follows some of the same principles you layout in your article. 

I do however think that if you name your parameters correctly their intent will be obvious. Another thing I like about optional/named parameters is their ability to be expressive on the calling side. Much like object initializers are used in the article link above so can optional/named parameters.

I guess I would concede the iPhone discussion saying there are two buttons. The [] button and the screen itself. I get your point about simplicity I am just having a hard time drawing the parallel between hardware and software.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57820" rel="nofollow">@John Sonmez </a><br />
I completely agree with Wanja on the use of enumerations to help simplify the API and make it more expressive.</p>
<p>I also want to note that I agree with you John, on the trying to make a cleaner API. One thing I am a fan of is the new push for fluent interfaces. (<a href="http://msdn.microsoft.com/en-us/magazine/ee291514.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/ee291514.aspx</a>) I think in some ways this follows some of the same principles you layout in your article. </p>
<p>I do however think that if you name your parameters correctly their intent will be obvious. Another thing I like about optional/named parameters is their ability to be expressive on the calling side. Much like object initializers are used in the article link above so can optional/named parameters.</p>
<p>I guess I would concede the iPhone discussion saying there are two buttons. The [] button and the screen itself. I get your point about simplicity I am just having a hard time drawing the parallel between hardware and software.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

