<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Are Helper Classes Evil?</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx</link><description>First off, a definition: A helper class is a class filled with static methods. It is usually used to isolate a "useful" algorithm. I've seen them in nearly every bit of code I've reviewed. For the record, I consider the use of helper classes to be an</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Are Helper Classes Evil? </title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#461410</link><pubDate>Tue, 06 Sep 2005 17:51:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:461410</guid><dc:creator>Lorenzo Barbieri @ UGIblogs!</dc:creator><description /></item><item><title>re: Are Helper Classes Evil?</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#461417</link><pubDate>Tue, 06 Sep 2005 17:58:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:461417</guid><dc:creator>matt</dc:creator><description>Hmmm.... interesting. But I'm not sure that I agree with your definition. &lt;br&gt;&lt;br&gt;So if I take a helper class and convert all static methods to instance methods, does that now make it less evil? I create all of my &amp;quot;helper classes&amp;quot; in such a way that they need to be instatiated and passed references to the particular instance of the class that they are &amp;quot;helping&amp;quot;. Would this still be considered evil by your standards?&lt;br&gt;</description></item><item><title>re: Are Helper Classes Evil?</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#461426</link><pubDate>Tue, 06 Sep 2005 18:05:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:461426</guid><dc:creator>Jim Arnold</dc:creator><description>Nice to see someone from Microsoft making a stand against this anti-pattern!  Now maybe you could have a word with some of your colleagues :-)&lt;br&gt;&lt;br&gt;Jim</description></item><item><title>re: Are Helper Classes Evil?</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#461427</link><pubDate>Tue, 06 Sep 2005 18:07:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:461427</guid><dc:creator>Nate</dc:creator><description>This is all good and all, but if helper classes are undesireable, where do you put miscellaneous code that you would normally put in a helper class?  Where does that method go that say, helps encode a URL?  Or that function that converts an array to a comma delimited list?  Or in C#, that wrapper for a certain Win32 API?&lt;br&gt;&lt;br&gt;In all practicality, I find that I often have these piddely tasks that don't really lend themselves to encapsulation within an object and are pretty much on their own, but are called from myriad places.&lt;br&gt;&lt;br&gt;If I was coding in C++, I would place it outside of a class, but languages like C# and VB.NET don't allow me to do that.  Does it violate OO principles?  Of course it does.  But OO principles are not meant to be a straightjacket.&lt;br&gt;&lt;br&gt;All that said, I do agree that if they show up in a UML diagram, your helper class is probably doing more than isolating a &amp;quot;piddely task&amp;quot; and that something is probably wrong.</description></item><item><title>re: Are Helper Classes Evil?</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#461468</link><pubDate>Tue, 06 Sep 2005 19:23:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:461468</guid><dc:creator>William Sullivan</dc:creator><description>I can think of one case where helper classes are useful...  Code re-use in a company.  For instance, a company has a policy on how its programs will access and write to the registry.  You wouldn't want some products in the company saving its data in HKLM/Software/CompanyName/ProductName and some under .../Software/ProductName and some .../&amp;quot;Company Name&amp;quot;/&amp;quot;Product Name&amp;quot;.  So you create a &amp;quot;helper class&amp;quot; that has static functions for accessing data in the registry.  It could be designed to be instantiatable and extendable, but what would be the advantage?  Another class could implement the companies' policy on encryption, another for database access; each could be created in a similar way, under different namespaces in the same DLL.  That package can then be used by each developer.  I would agree that having a single catch-all for all of these functions would not be good OO, but this method would still violate some of the principles you outlined in your post...</description></item><item><title>re: Are Helper Classes Evil?</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#461627</link><pubDate>Wed, 07 Sep 2005 00:19:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:461627</guid><dc:creator>NickMalik</dc:creator><description>I'll try to answer more than one comment in this reply:  &lt;br&gt;To Matt: would making the methods non-static... would that be less evil?  Yes.  You are no longer in violation of the Open-Closed Principle.  Would the ability to pass the object to the classes that use it make it less evil?  Yes: you are now using Dependency Injection.  It is also a lot more testable.&lt;br&gt;&lt;br&gt;To Nate: I appreciate your practicality.  However, I don't agree that there are many cases where code is truly miscellaneous.  Encoding a URL is part of a URL object.  Converting an array to a comma-delimeted list is an extension of the array object itself.  Wrappers for API calls are usually best when created as private methods inside the class that needs to call the API.&lt;br&gt;&lt;br&gt;To William Sullivan: The largest reusable code base that all your developers are already using is the .Net Framework.  The vast majority of the framework uses instantiated classes, not static helper classes (there are exceptions, unfortunately).  So, the need for reuse is NOT a good argument for helper classes.</description></item><item><title>re: Are Helper Classes Evil?</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#461928</link><pubDate>Wed, 07 Sep 2005 17:27:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:461928</guid><dc:creator>Nate</dc:creator><description>I agree that ideally, URL encoding should be in a URL object and so on, but what about the practical scenario where objects like URL and array objects are provided by the framework, and one does not have the ability to modify the framework?&lt;br&gt;&lt;br&gt;Take say the .NET array object; I want to use that object but I do not have the ability to add a method that does a custom parse job.  Subclassing the array to simply aggregate behavior without modifying existing behavior strikes me as overkill.&lt;br&gt;&lt;br&gt;I emphatically agree that 99% of the time, it probably isn't necessary to use a helper class, and that most of the time that are abused; but that does not detract from the other 1% of the time.&lt;br&gt;&lt;br&gt;As for William Sullivan's argument, I'd like to hear how you would approach the specific scenario he proposed, as that is exactly the kind of scenario for which I find helper clases useful.  I'm honestly curious.</description></item><item><title>re: Are Helper Classes Evil?</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#461944</link><pubDate>Wed, 07 Sep 2005 18:08:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:461944</guid><dc:creator>Nate</dc:creator><description>Just to add another example, say that you are writing .NET code to retrieve the string for a Win32 error message.  This requires calling the Win32 API FormatMessage() and doing some non-trivial munging on the results to get the string into a .NET string.&lt;br&gt;&lt;br&gt;This is best done in a helper class because there really isn't any object to instantiate per se, and it is non-trivial so you would not want to duplicate this code in every place that you would want to use it.  Granted, you could write code that looked like this:&lt;br&gt;&lt;br&gt;wec = new Win32ErrorCodeConverter();&lt;br&gt;string message = wec.Convert(errorCode);&lt;br&gt;&lt;br&gt;...but this would result in an instance object that is no different than any other instance; a gross misuse of OOP.&lt;br&gt;&lt;br&gt;Another good example of a helper class in .NET is the System.Convert class.  The only other place I could imagine putting that functionality would be on the root Object class itself.</description></item><item><title>re: Are Helper Classes Evil?</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#462056</link><pubDate>Wed, 07 Sep 2005 21:43:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462056</guid><dc:creator>NickMalik</dc:creator><description>William and Nate:&lt;br&gt;Please see my follow-up post:&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/nickmalik/archive/2005/09/07/462054.aspx"&gt;http://blogs.msdn.com/nickmalik/archive/2005/09/07/462054.aspx&lt;/a&gt;</description></item><item><title>re: Are Helper Classes Evil?</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#462057</link><pubDate>Wed, 07 Sep 2005 21:44:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462057</guid><dc:creator>NickMalik</dc:creator><description>William and Nate:&lt;br&gt;Please see my follow-up post</description></item><item><title>The Evils of Helper Classes</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#463403</link><pubDate>Sat, 10 Sep 2005 19:52:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:463403</guid><dc:creator>Mike's Dump</dc:creator><description>I came across a couple of good posts here and here on helper classes.&lt;br&gt;Although I don't believe helper...</description></item><item><title>Helpers and Utils are CodeSmell's</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#710708</link><pubDate>Mon, 21 Aug 2006 15:38:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:710708</guid><dc:creator>Just Coding</dc:creator><description>I never like too much the concept of &amp;amp;quot;helper classes&amp;amp;quot;, &amp;amp;amp;nbsp; First of all I tried to found some written...</description></item><item><title>The Evils of Helper Classes &amp;laquo; Mike&amp;#8217;s Dump</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#4836480</link><pubDate>Sun, 09 Sep 2007 02:58:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4836480</guid><dc:creator>The Evils of Helper Classes « Mike’s Dump</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://mikesdump.wordpress.com/2005/09/10/the-evils-of-helper-classes/"&gt;http://mikesdump.wordpress.com/2005/09/10/the-evils-of-helper-classes/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Guru PHP  &amp;raquo; Blog Archive   &amp;raquo; Helpers are unhelpful</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#8834015</link><pubDate>Tue, 05 Aug 2008 16:36:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8834015</guid><dc:creator>Guru PHP  &amp;raquo; Blog Archive   &amp;raquo; Helpers are unhelpful</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://blog.guru-php.com/2008/08/helpers-are-unhelpful/"&gt;http://blog.guru-php.com/2008/08/helpers-are-unhelpful/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Helpers and managers &amp;laquo; Big Ball of Mud</title><link>http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx#9529572</link><pubDate>Thu, 02 Apr 2009 22:15:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9529572</guid><dc:creator>Helpers and managers &amp;laquo; Big Ball of Mud</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://bigballofmud.wordpress.com/2009/04/02/helpers-and-managers/"&gt;http://bigballofmud.wordpress.com/2009/04/02/helpers-and-managers/&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>