<?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: Single-Responsibility Versus Needless Complexity</title>
	<atom:link href="http://lostechies.com/rayhouston/2008/10/05/single-responsibility-versus-needless-complexity/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/rayhouston/2008/10/05/single-responsibility-versus-needless-complexity/</link>
	<description></description>
	<lastBuildDate>Tue, 02 Apr 2013 20:36:56 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Gabriele Lana</title>
		<link>http://lostechies.com/rayhouston/2008/10/05/single-responsibility-versus-needless-complexity/#comment-103</link>
		<dc:creator>Gabriele Lana</dc:creator>
		<pubDate>Mon, 06 Oct 2008 20:54:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/rhouston/archive/2008/10/05/single-responsibility-versus-needless-complexity.aspx#comment-103</guid>
		<description>I agree with you, but in the example above IMHO the SRP should be applied

We can split the method in three distinct sections with three distinct purposes

public bool Login(string username, string password) {
    // find the user object
    var user = userRepo.GetUserByUsername(username);
    if(user == null)
        return false;

    // validate the user login
    if (loginValidator.IsValid(user, password))
        return true;

    // apply the login failures&#039;s business logic
    user.FailedLoginAttempts++;
    if (user.FailedLoginAttempts &gt;= 3)
        user.LockedOut = true;

    return false;
}

The user object can be passed as an argument (so that the Login method can be more easely tested without mock/stub), the caller can retrieve the user object from the repo, and the repo can return a NotFoundUser (null object pattern) which should fail all the login validation 

The last section smells like &quot;Feature Envy&quot;, maybe the &#039;user&#039; should deal with the login failures&#039;s business logic

public bool Login(User user, string password) {
    if (loginValidator.IsValid(user, password)) {
        return true;
    }
    user.FailedLogin();
    return false;
}

Last steps:
- We can/should inline loginValidator.isValid or move it to this class
- &#039;Login&#039; seems to me more a &#039;do&#039; method then a &#039;query&#039; method

In the end, something like this

public void Login(User user, string password) {
    if (IsNotTheUserPassword(user, password)) {
        user.FailedLogin();
        throw new LoginFailedException(user, password);
    }
}

Sorry for my bad english</description>
		<content:encoded><![CDATA[<p>I agree with you, but in the example above IMHO the SRP should be applied</p>
<p>We can split the method in three distinct sections with three distinct purposes</p>
<p>public bool Login(string username, string password) {<br />
    // find the user object<br />
    var user = userRepo.GetUserByUsername(username);<br />
    if(user == null)<br />
        return false;</p>
<p>    // validate the user login<br />
    if (loginValidator.IsValid(user, password))<br />
        return true;</p>
<p>    // apply the login failures&#8217;s business logic<br />
    user.FailedLoginAttempts++;<br />
    if (user.FailedLoginAttempts >= 3)<br />
        user.LockedOut = true;</p>
<p>    return false;<br />
}</p>
<p>The user object can be passed as an argument (so that the Login method can be more easely tested without mock/stub), the caller can retrieve the user object from the repo, and the repo can return a NotFoundUser (null object pattern) which should fail all the login validation </p>
<p>The last section smells like &#8220;Feature Envy&#8221;, maybe the &#8216;user&#8217; should deal with the login failures&#8217;s business logic</p>
<p>public bool Login(User user, string password) {<br />
    if (loginValidator.IsValid(user, password)) {<br />
        return true;<br />
    }<br />
    user.FailedLogin();<br />
    return false;<br />
}</p>
<p>Last steps:<br />
- We can/should inline loginValidator.isValid or move it to this class<br />
- &#8216;Login&#8217; seems to me more a &#8216;do&#8217; method then a &#8216;query&#8217; method</p>
<p>In the end, something like this</p>
<p>public void Login(User user, string password) {<br />
    if (IsNotTheUserPassword(user, password)) {<br />
        user.FailedLogin();<br />
        throw new LoginFailedException(user, password);<br />
    }<br />
}</p>
<p>Sorry for my bad english</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Van Ryswyck</title>
		<link>http://lostechies.com/rayhouston/2008/10/05/single-responsibility-versus-needless-complexity/#comment-102</link>
		<dc:creator>Jan Van Ryswyck</dc:creator>
		<pubDate>Mon, 06 Oct 2008 18:35:47 +0000</pubDate>
		<guid isPermaLink="false">/blogs/rhouston/archive/2008/10/05/single-responsibility-versus-needless-complexity.aspx#comment-102</guid>
		<description>I&#039;d thought I&#039;s take this for a spin:

http://elegantcode.com/2008/10/06/refactoring-exercise-the-single-responsibility-principle-vs-needless-complexity/

Let me know what you guys think.</description>
		<content:encoded><![CDATA[<p>I&#8217;d thought I&#8217;s take this for a spin:</p>
<p><a href="http://elegantcode.com/2008/10/06/refactoring-exercise-the-single-responsibility-principle-vs-needless-complexity/" rel="nofollow">http://elegantcode.com/2008/10/06/refactoring-exercise-the-single-responsibility-principle-vs-needless-complexity/</a></p>
<p>Let me know what you guys think.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://lostechies.com/rayhouston/2008/10/05/single-responsibility-versus-needless-complexity/#comment-101</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Mon, 06 Oct 2008 11:42:44 +0000</pubDate>
		<guid isPermaLink="false">/blogs/rhouston/archive/2008/10/05/single-responsibility-versus-needless-complexity.aspx#comment-101</guid>
		<description>Funny, I was having a very similar conversation with a co-worker late last week.  Mike is an extremely smart developer and adheres to SOLID practices without having to think about it.  He was very proud of a solution to a particularly nasty problem we&#039;ve had recently, but when he presented his solution to the more junior developers on the team, it was met with a deafening silence.  While his solution was EXTREMELY flexible, the junior guys just didn&#039;t get it due to it&#039;s complexity.  There were simply too many relationships for the young guys to follow and they quickly became frustrated.  What we had was a deer in the headlights scenario.

Now, we&#039;re working on bringing everyone&#039;s knowledge of good OO design up a notch or two, but it&#039;s going to take time.  For now, we know for certain that some parts of our application are going to change, so Mike and I worked for a while to come up with a good solution that just applied to those parts of the app.  We cut the object diagram down by about 80% and STILL had a flexible solution that solved all the problems that we knew (or suspected) would change.  When we went back to the developers, they were MUCH more receptive.

What gets me is that Mike knows better.  We&#039;ve been doing a great job with agile practices for about six months now, and Mike knows (or should know) not to design his application for some far off, grandiose idea of what could be a year or two down the road.  Chances are that 95% of the flexibility provided by the initial design would never be needed.</description>
		<content:encoded><![CDATA[<p>Funny, I was having a very similar conversation with a co-worker late last week.  Mike is an extremely smart developer and adheres to SOLID practices without having to think about it.  He was very proud of a solution to a particularly nasty problem we&#8217;ve had recently, but when he presented his solution to the more junior developers on the team, it was met with a deafening silence.  While his solution was EXTREMELY flexible, the junior guys just didn&#8217;t get it due to it&#8217;s complexity.  There were simply too many relationships for the young guys to follow and they quickly became frustrated.  What we had was a deer in the headlights scenario.</p>
<p>Now, we&#8217;re working on bringing everyone&#8217;s knowledge of good OO design up a notch or two, but it&#8217;s going to take time.  For now, we know for certain that some parts of our application are going to change, so Mike and I worked for a while to come up with a good solution that just applied to those parts of the app.  We cut the object diagram down by about 80% and STILL had a flexible solution that solved all the problems that we knew (or suspected) would change.  When we went back to the developers, they were MUCH more receptive.</p>
<p>What gets me is that Mike knows better.  We&#8217;ve been doing a great job with agile practices for about six months now, and Mike knows (or should know) not to design his application for some far off, grandiose idea of what could be a year or two down the road.  Chances are that 95% of the flexibility provided by the initial design would never be needed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://lostechies.com/rayhouston/2008/10/05/single-responsibility-versus-needless-complexity/#comment-100</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Mon, 06 Oct 2008 06:11:44 +0000</pubDate>
		<guid isPermaLink="false">/blogs/rhouston/archive/2008/10/05/single-responsibility-versus-needless-complexity.aspx#comment-100</guid>
		<description>Yeah - what sean said

There is a quote along the lines of &quot;being made a fool of the first time is OK&quot; subsequent time not so

i.e. wait until a scenario occurs that suggests you need to add in some extra flexibility rather than assume it needs it upfront</description>
		<content:encoded><![CDATA[<p>Yeah &#8211; what sean said</p>
<p>There is a quote along the lines of &#8220;being made a fool of the first time is OK&#8221; subsequent time not so</p>
<p>i.e. wait until a scenario occurs that suggests you need to add in some extra flexibility rather than assume it needs it upfront</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Scally</title>
		<link>http://lostechies.com/rayhouston/2008/10/05/single-responsibility-versus-needless-complexity/#comment-99</link>
		<dc:creator>Sean Scally</dc:creator>
		<pubDate>Mon, 06 Oct 2008 02:55:17 +0000</pubDate>
		<guid isPermaLink="false">/blogs/rhouston/archive/2008/10/05/single-responsibility-versus-needless-complexity.aspx#comment-99</guid>
		<description>Good points made there.

Actually, Uncle Bob&#039;s PPP book discusses this very topic in greater detail in the Agile Design / OCP chapters, i believe, under the topic of &quot;taking the first bullet&quot;.

http://anydiem.com/2008/10/05/needless-complexity-and-taking-the-first-bullet/</description>
		<content:encoded><![CDATA[<p>Good points made there.</p>
<p>Actually, Uncle Bob&#8217;s PPP book discusses this very topic in greater detail in the Agile Design / OCP chapters, i believe, under the topic of &#8220;taking the first bullet&#8221;.</p>
<p><a href="http://anydiem.com/2008/10/05/needless-complexity-and-taking-the-first-bullet/" rel="nofollow">http://anydiem.com/2008/10/05/needless-complexity-and-taking-the-first-bullet/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray Houston</title>
		<link>http://lostechies.com/rayhouston/2008/10/05/single-responsibility-versus-needless-complexity/#comment-98</link>
		<dc:creator>Ray Houston</dc:creator>
		<pubDate>Mon, 06 Oct 2008 00:25:28 +0000</pubDate>
		<guid isPermaLink="false">/blogs/rhouston/archive/2008/10/05/single-responsibility-versus-needless-complexity.aspx#comment-98</guid>
		<description>@chad - yeah, I agree. The point I&#039;m trying to make here is not to abstract just to be abstract. If you do, you&#039;ll have a lot of complexity that just ends up being waste. I&#039;ve been down that road a time or two.</description>
		<content:encoded><![CDATA[<p>@chad &#8211; yeah, I agree. The point I&#8217;m trying to make here is not to abstract just to be abstract. If you do, you&#8217;ll have a lot of complexity that just ends up being waste. I&#8217;ve been down that road a time or two.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad Myers</title>
		<link>http://lostechies.com/rayhouston/2008/10/05/single-responsibility-versus-needless-complexity/#comment-97</link>
		<dc:creator>Chad Myers</dc:creator>
		<pubDate>Sun, 05 Oct 2008 23:14:33 +0000</pubDate>
		<guid isPermaLink="false">/blogs/rhouston/archive/2008/10/05/single-responsibility-versus-needless-complexity.aspx#comment-97</guid>
		<description>Whomever asked about SRP had good instincts, though. That code does stick out like a sore thumb.

I&#039;d say the second any change came up that involved any more complexity in how failed login attempts are calculated or reset, refactor that into a separate class somehow.

Also, the hard-coded &#039;3&#039; might need to become configurable -- also an excuse to refactor this part.</description>
		<content:encoded><![CDATA[<p>Whomever asked about SRP had good instincts, though. That code does stick out like a sore thumb.</p>
<p>I&#8217;d say the second any change came up that involved any more complexity in how failed login attempts are calculated or reset, refactor that into a separate class somehow.</p>
<p>Also, the hard-coded &#8217;3&#8242; might need to become configurable &#8212; also an excuse to refactor this part.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
