<?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>Can you take the single responsibility principle too far?</title><link>http://blogs.msdn.com/agilemonkey/archive/2008/03/28/can-you-take-the-srp-too-far.aspx</link><description>This morning, I had a conversation with a colleague of mine who has recently started using EDD about "exposing things just for the purpose of testing." Although I have run across the odd occasion where I may need to add a get property to a class in order</description><dc:language>en-CA</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Can you take the single responsibility principle too far?</title><link>http://blogs.msdn.com/agilemonkey/archive/2008/03/28/can-you-take-the-srp-too-far.aspx#8341864</link><pubDate>Fri, 28 Mar 2008 18:05:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8341864</guid><dc:creator>Paul Hammond</dc:creator><description>&lt;p&gt;I've labored over your question for literally MINUTES, and I think I have the answer.&lt;/p&gt;
&lt;p&gt;Here goes. &amp;nbsp;Can you take the single responsiblilty principle too far?&lt;/p&gt;
&lt;p&gt;&amp;quot;Yes. &amp;nbsp;Or no.&amp;quot;&lt;/p&gt;
&lt;p&gt;Hope that helps.&lt;/p&gt;</description></item><item><title>re: Can you take the single responsibility principle too far?</title><link>http://blogs.msdn.com/agilemonkey/archive/2008/03/28/can-you-take-the-srp-too-far.aspx#8341946</link><pubDate>Fri, 28 Mar 2008 18:46:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8341946</guid><dc:creator>Keith Robertson</dc:creator><description>&lt;p&gt;Yes, the principle can definitely be taken too far, and I agree with your colleague in this case. For classes, I think the proper focus is not it should &amp;quot;do one thing&amp;quot; but instead &amp;quot;have one responsibility,&amp;quot; but the performance of that responsibility can involve many factors. I would say your original PourWaterAction class meets that test. That is, it manages a particular action, including validating its parameters and performing the action. Those two functions are tightly bound and belong together.&lt;/p&gt;
&lt;p&gt;Methods should more clearly &amp;quot;do one thing,&amp;quot; but here again it can be taken too far. I occasionally hear a dogma that methods should never be more than 20 lines, and you should break up larger methods. But that's an arbitrary number and violates the 0-1-infinity principle. I believe a method should perform one logical action, even if it takes 200 lines to do it. Any subparts independently useful should be factored out, of course, but if a subpart only makes sense within the context of that function, then it only adds complexity to separate it to a new method.&lt;/p&gt;</description></item><item><title>re: Can you take the single responsibility principle too far?</title><link>http://blogs.msdn.com/agilemonkey/archive/2008/03/28/can-you-take-the-srp-too-far.aspx#8342037</link><pubDate>Fri, 28 Mar 2008 19:36:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8342037</guid><dc:creator>casper</dc:creator><description>&lt;p&gt;Keith - how do you go about properly testing the class if it takes care of validation and performing an action? Do you really just create get properties for the sole purpose of being able to verify that the validation worked?&lt;/p&gt;
</description></item><item><title>re: Can you take the single responsibility principle too far?</title><link>http://blogs.msdn.com/agilemonkey/archive/2008/03/28/can-you-take-the-srp-too-far.aspx#8342042</link><pubDate>Fri, 28 Mar 2008 19:40:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8342042</guid><dc:creator>casper</dc:creator><description>&lt;p&gt;Paul - how about another question then, in *this* case do you think the class should be split in two?&lt;/p&gt;
</description></item><item><title>re: Can you take the single responsibility principle too far?</title><link>http://blogs.msdn.com/agilemonkey/archive/2008/03/28/can-you-take-the-srp-too-far.aspx#8342236</link><pubDate>Fri, 28 Mar 2008 21:57:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8342236</guid><dc:creator>ploeh</dc:creator><description>&lt;p&gt;I agree with Keith.&lt;/p&gt;
&lt;p&gt;Concerning how to test parsing of input, you'd need to identify all the Equivalence Classes that correspond to your Boundary Values, and then test each scenario by itself (or, if you feel like being thorough, all permutations).&lt;/p&gt;
&lt;p&gt;If this is is difficult to set up (e.g. complex string concatenation of the input parameters), you should create a Test-Specific API for use in your tests.&lt;/p&gt;
&lt;p&gt;Regarding validation, it really depends on what it is that you need to test, but under the assumption that a method does SOME work, it's only a matter of design how you verify that work: Verification can happen on an object's post-test state, Direct, or Indirect Output, although you might need to tweak your design to enable interception of Indirect Output (i.e. use IoC/DI).&lt;/p&gt;
&lt;p&gt;In the case of a console application, my first design thought would probably be to let the application itself act as a Humble Executable that delegates all work to a testable library, but for an example of how to test the Indirect Output of a console application without such indirection, see my post at &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/ploeh/archive/2006/10/21/ConsoleUnitTesting.aspx"&gt;http://blogs.msdn.com/ploeh/archive/2006/10/21/ConsoleUnitTesting.aspx&lt;/a&gt;&lt;/p&gt;</description></item><item><title>re: Can you take the single responsibility principle too far?</title><link>http://blogs.msdn.com/agilemonkey/archive/2008/03/28/can-you-take-the-srp-too-far.aspx#9002937</link><pubDate>Fri, 17 Oct 2008 15:29:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9002937</guid><dc:creator>c.c</dc:creator><description>&lt;p&gt;Well, from my point of view, It is not a good design to make a object who performe the &amp;quot;ACTION&amp;quot; to parse the input parameter in the first place. Hence it leads to the diffculty of the &amp;quot;TEST&amp;quot; &lt;/p&gt;
&lt;p&gt;It looks like there are some advantages such that: we just give the input to each object, they understand it and then do the job accordingly. And When new &amp;quot;ACTION&amp;quot; is come in, new parse method is automatic added in.&lt;/p&gt;
&lt;p&gt;However, this lead to the problem: how the different &amp;quot;ACTION&amp;quot; object understanding the input parameters.&lt;/p&gt;
&lt;p&gt;Some question: 1) How to decide to which the input should be send (i.e., the sequence order of ACTION) Since only &amp;quot;ACTION&amp;quot; object understand the input parameter 2) what happens if the two &amp;quot;ACTION&amp;quot; require the same parameters? this lead to the problem that if one change it way of phase, then all the other need change also.&lt;/p&gt;
&lt;p&gt;Actually, the original design has departed from the principle &amp;quot;single responsibility&amp;quot;, as parsing the input and do the action is actually tow responsibility. &lt;/p&gt;
&lt;p&gt;I think the &amp;quot;right&amp;quot; should be a class which is dedicated to deal with the input phrase and init the &amp;quot;ACTION&amp;quot; object, and each &amp;quot;action&amp;quot; class publish its &amp;quot;input data structure&amp;quot; (and from the point view of efficience, it is better to public the valid method as static). The phrase object will fill the &amp;quot;data&amp;quot; according to the input, and call the valid of action class to check if the input is ok and init the related objects.&lt;/p&gt;</description></item></channel></rss>