<?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: PTOM: The Single Responsibility Principle</title>
	<atom:link href="http://lostechies.com/seanchambers/2008/03/15/ptom-single-responsibility-principle/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/seanchambers/2008/03/15/ptom-single-responsibility-principle/</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: schambers</title>
		<link>http://lostechies.com/seanchambers/2008/03/15/ptom-single-responsibility-principle/#comment-226</link>
		<dc:creator>schambers</dc:creator>
		<pubDate>Fri, 25 Apr 2008 17:21:13 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2008/03/15/ptom-single-responsibility-principle.aspx#comment-226</guid>
		<description>@Vic

Not really. I am in palm coast so ONETUG is about an hour and a half drive. With the recent rise in gas prices I find it hard to make the trek.

JAXDUG is a lot closer to me and I have done one presentation there last month. I&#039;ll probably go back soon and do some more presentations on more OSS.

I was in orlando for the code camp recently. That was really neat.</description>
		<content:encoded><![CDATA[<p>@Vic</p>
<p>Not really. I am in palm coast so ONETUG is about an hour and a half drive. With the recent rise in gas prices I find it hard to make the trek.</p>
<p>JAXDUG is a lot closer to me and I have done one presentation there last month. I&#8217;ll probably go back soon and do some more presentations on more OSS.</p>
<p>I was in orlando for the code camp recently. That was really neat.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Victor Moran</title>
		<link>http://lostechies.com/seanchambers/2008/03/15/ptom-single-responsibility-principle/#comment-225</link>
		<dc:creator>Victor Moran</dc:creator>
		<pubDate>Fri, 25 Apr 2008 14:54:01 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2008/03/15/ptom-single-responsibility-principle.aspx#comment-225</guid>
		<description>Thanks Sean; yeah, I figured your intentions were to make it easier on the example (shoulda mentioned that).

This got me reading your other blog posts; pretty good stuff.  I enjoyed the &quot;Open Source&quot; thing - although the comments sorta strayed into the weeds there toward the end.  Were you thanking &quot;Joe Healy&quot; (the &quot;Fish&quot;)?  If ya see him, tell him Vic from The Fund says &quot;hey&quot;!

Anyway I&#039;m basically in agreement with you though, and will probably add some stuff like I posted on Mats Helander&#039;s blog.  

BTW, do you appear regularly at ONETUG?

Kinda off-topic, so apologies for taking up the space...</description>
		<content:encoded><![CDATA[<p>Thanks Sean; yeah, I figured your intentions were to make it easier on the example (shoulda mentioned that).</p>
<p>This got me reading your other blog posts; pretty good stuff.  I enjoyed the &#8220;Open Source&#8221; thing &#8211; although the comments sorta strayed into the weeds there toward the end.  Were you thanking &#8220;Joe Healy&#8221; (the &#8220;Fish&#8221;)?  If ya see him, tell him Vic from The Fund says &#8220;hey&#8221;!</p>
<p>Anyway I&#8217;m basically in agreement with you though, and will probably add some stuff like I posted on Mats Helander&#8217;s blog.  </p>
<p>BTW, do you appear regularly at ONETUG?</p>
<p>Kinda off-topic, so apologies for taking up the space&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: schambers</title>
		<link>http://lostechies.com/seanchambers/2008/03/15/ptom-single-responsibility-principle/#comment-224</link>
		<dc:creator>schambers</dc:creator>
		<pubDate>Fri, 18 Apr 2008 14:15:14 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2008/03/15/ptom-single-responsibility-principle.aspx#comment-224</guid>
		<description>@Victor, interesting points. You could have written a whole post on that alone.

The whole reason that checkingaccount has no implementation is because this is an example. I&#039;m sure if I would have been writing actual classes here everything would have ended up much different.

The whole reason that I used this was to keep it as simple as possible while still illustrating my point.

Excellent points however.</description>
		<content:encoded><![CDATA[<p>@Victor, interesting points. You could have written a whole post on that alone.</p>
<p>The whole reason that checkingaccount has no implementation is because this is an example. I&#8217;m sure if I would have been writing actual classes here everything would have ended up much different.</p>
<p>The whole reason that I used this was to keep it as simple as possible while still illustrating my point.</p>
<p>Excellent points however.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Victor Moran</title>
		<link>http://lostechies.com/seanchambers/2008/03/15/ptom-single-responsibility-principle/#comment-223</link>
		<dc:creator>Victor Moran</dc:creator>
		<pubDate>Fri, 18 Apr 2008 12:59:12 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2008/03/15/ptom-single-responsibility-principle.aspx#comment-223</guid>
		<description>The 1st problem I see is the acceptance of an interface (&quot;IBankAccount&quot;) as a parameter; naughty boy (ha!).  Are you expecting anything other than a bank account to implement this interface?  If not, no need for the extra complexity.  You want a bank account (type that &quot;acts like&quot; a bank account), not just something that &quot;looks like&quot; a bank account on the surface - especially in this sensitive context.  This is the danger of assuming interfaces specify contracts - that the object behind the interface will be in the proper functional/semantic context expected by the client (THAT&#039;S the difference between &quot;contract&quot; and mere syntatic resemblance).  Conversely, there&#039;s no way to know for sure that your overriding functionality isn&#039;t malicious either, but it&#039;s a safer bet (and more under your control).

The realization that not all bank accounts pay interest is the 1st thing that shoulda happened when modeling &quot;BankAccount&quot;; then would follow the move from the general to the specific.  Figuring this out later is OK I guess, but is really just determining that &quot;CheckingAccount&quot; doesn&#039;t have that feature.  

&quot;Colin Jack&quot;s comments got me thinkng, but then I realized that responsibility separation doesn&#039;t have to mean &quot;outside the fam&quot;, so inheritance looks like a reasonable way to breal out responsibility.  He has a point though on the whole &quot;implementation vs interface&quot; thing.  Actually this is a bad example because if anyone were to look at this class diagram, they&#039;d ask why &quot;CheckingAccount&quot; has no implementation (&quot;class proliferation&quot; problem).  From this look (if the names weren&#039;t attached), you&#039;d logically conclude that a savings account is just a specialized checking account.  This represents an impedance mismatch between technical and business worlds.  In the &quot;real world&quot;, savings accounts came 1st,  then checking accounts, which in business seems normal, but plays havoc on the OO-minded because the newer thing should extend capabilities, not taking them away (like the ability to acrue interest going away).  Designers would then have to flipSome checking accounts are indeed interest-baring as well so leaving it there would help their refactoring down the road, but just an example of how the example could lead to confusion about the problem, especially when the questionable things centr around what the demo is aluuding to (responsibility in this case).

Anyway (whew!), I think the problem people have with adhering to this seemingly simple principle stems from the another impedance mismatch between responsibilities and reasons to change.  There has to be some kind of &quot;apples-to-apples&quot; endeavor to get on equal terms before you can even compare the 2.  Reasons to change can be anything; in this case, the &quot;BankAccount&quot; class&#039;s &quot;Deposit&quot; or it&#039;s &quot;Withdraw&quot; truly represent to distinct functions (and hence, reasons to change.  If I change the &quot;Withdraw&quot; &#039;responsibility&#039;, it affects &quot;BankAccount&quot; &#039;clients&#039; (like my wife) who only care about this activity - which is OK (nothing broken yet), but it also affects those only interested in making deposits (like my company&#039;s automatic salary deposit system) because this class&#039;s code has been cracked open (possibily introducing subtle bugs to other than the target code) and now has to be regression tested, redeployed, etc., which affects all clients of the class.  Now we&#039;ve violated the defined intention of SRP, which is to avoid this by the isolation of responsibilities/reasons to change.  I have 2 &quot;reasons to change&quot; but still only 1 stated responsibility to &quot;manage the account&quot;.

By the same token, the granularity of the responsibility of &quot;managing a bank account&quot; that&#039;s being encapsulated/represented by &quot;BankAccount&quot; is really relative, isn&#039;t it?  Withdrawing and depositing at this granularity level, represent 2 entirely different concerns; under this interpretation, does this mean that &quot;BankAccount&quot; is no longer singly responsible/should be broken out?  If the responsibility is interpreted as &quot;all things that happen to a bank account&quot;, then we&#039;re OK, and changes to either &quot;Deposit&quot; and &quot;Withdraw&quot; functionality can be &#039;interpreted&#039; as non-disruptive beacuse they combine to represent a single resposibility.

In the extreme, strict adherence to this principle would mean that each method would be in a class by itself because technically/depending on your altitude/distance from the abstraction, they can be seen as separate responsibilities and reasons to change.  Concersely, another extremity is you can move further away and say that an entire system has a single responsibility and should all be in 1 class!  

I think something that helps reduce this impedance mismatch (in conjunction with thinking about 
&#039;reasons to change&quot;) - as alluded to above - is focusing on:
- Data shared between methods
- The impact to the bject&#039;s client/user of making a change.
- Usage scenarios
W/ respect to the &quot;BankAccount&quot; model: that 1st extreme case (all methods in a separate class) provides maximum isolation of the client from change, but results in loss of encapsulation because multiple classes are operating on the bank account. In the 2nd extreme case (all methods in 1 class), this solves the encapsulation problem, but potentially affects every single client using the system when things change.

We have to come up with &quot;reasonable&quot; solutions, so thinking about all 4 things (reasons to change, shared data, client impacts, usage scenarios) seems a more noteworthy voice of &quot;reason&quot;.  Applying these, you seem to end up not with separate &quot;Withdrawl&quot; and &quot;Deposit&quot; classes or a big &quot;Bank&quot; class (e.g. w/ &quot;Deposit&quot; method that also takes the account number), but 2 (parent-child) account classes that seems to reasonably satisfy SRP.</description>
		<content:encoded><![CDATA[<p>The 1st problem I see is the acceptance of an interface (&#8220;IBankAccount&#8221;) as a parameter; naughty boy (ha!).  Are you expecting anything other than a bank account to implement this interface?  If not, no need for the extra complexity.  You want a bank account (type that &#8220;acts like&#8221; a bank account), not just something that &#8220;looks like&#8221; a bank account on the surface &#8211; especially in this sensitive context.  This is the danger of assuming interfaces specify contracts &#8211; that the object behind the interface will be in the proper functional/semantic context expected by the client (THAT&#8217;S the difference between &#8220;contract&#8221; and mere syntatic resemblance).  Conversely, there&#8217;s no way to know for sure that your overriding functionality isn&#8217;t malicious either, but it&#8217;s a safer bet (and more under your control).</p>
<p>The realization that not all bank accounts pay interest is the 1st thing that shoulda happened when modeling &#8220;BankAccount&#8221;; then would follow the move from the general to the specific.  Figuring this out later is OK I guess, but is really just determining that &#8220;CheckingAccount&#8221; doesn&#8217;t have that feature.  </p>
<p>&#8220;Colin Jack&#8221;s comments got me thinkng, but then I realized that responsibility separation doesn&#8217;t have to mean &#8220;outside the fam&#8221;, so inheritance looks like a reasonable way to breal out responsibility.  He has a point though on the whole &#8220;implementation vs interface&#8221; thing.  Actually this is a bad example because if anyone were to look at this class diagram, they&#8217;d ask why &#8220;CheckingAccount&#8221; has no implementation (&#8220;class proliferation&#8221; problem).  From this look (if the names weren&#8217;t attached), you&#8217;d logically conclude that a savings account is just a specialized checking account.  This represents an impedance mismatch between technical and business worlds.  In the &#8220;real world&#8221;, savings accounts came 1st,  then checking accounts, which in business seems normal, but plays havoc on the OO-minded because the newer thing should extend capabilities, not taking them away (like the ability to acrue interest going away).  Designers would then have to flipSome checking accounts are indeed interest-baring as well so leaving it there would help their refactoring down the road, but just an example of how the example could lead to confusion about the problem, especially when the questionable things centr around what the demo is aluuding to (responsibility in this case).</p>
<p>Anyway (whew!), I think the problem people have with adhering to this seemingly simple principle stems from the another impedance mismatch between responsibilities and reasons to change.  There has to be some kind of &#8220;apples-to-apples&#8221; endeavor to get on equal terms before you can even compare the 2.  Reasons to change can be anything; in this case, the &#8220;BankAccount&#8221; class&#8217;s &#8220;Deposit&#8221; or it&#8217;s &#8220;Withdraw&#8221; truly represent to distinct functions (and hence, reasons to change.  If I change the &#8220;Withdraw&#8221; &#8216;responsibility&#8217;, it affects &#8220;BankAccount&#8221; &#8216;clients&#8217; (like my wife) who only care about this activity &#8211; which is OK (nothing broken yet), but it also affects those only interested in making deposits (like my company&#8217;s automatic salary deposit system) because this class&#8217;s code has been cracked open (possibily introducing subtle bugs to other than the target code) and now has to be regression tested, redeployed, etc., which affects all clients of the class.  Now we&#8217;ve violated the defined intention of SRP, which is to avoid this by the isolation of responsibilities/reasons to change.  I have 2 &#8220;reasons to change&#8221; but still only 1 stated responsibility to &#8220;manage the account&#8221;.</p>
<p>By the same token, the granularity of the responsibility of &#8220;managing a bank account&#8221; that&#8217;s being encapsulated/represented by &#8220;BankAccount&#8221; is really relative, isn&#8217;t it?  Withdrawing and depositing at this granularity level, represent 2 entirely different concerns; under this interpretation, does this mean that &#8220;BankAccount&#8221; is no longer singly responsible/should be broken out?  If the responsibility is interpreted as &#8220;all things that happen to a bank account&#8221;, then we&#8217;re OK, and changes to either &#8220;Deposit&#8221; and &#8220;Withdraw&#8221; functionality can be &#8216;interpreted&#8217; as non-disruptive beacuse they combine to represent a single resposibility.</p>
<p>In the extreme, strict adherence to this principle would mean that each method would be in a class by itself because technically/depending on your altitude/distance from the abstraction, they can be seen as separate responsibilities and reasons to change.  Concersely, another extremity is you can move further away and say that an entire system has a single responsibility and should all be in 1 class!  </p>
<p>I think something that helps reduce this impedance mismatch (in conjunction with thinking about<br />
&#8216;reasons to change&#8221;) &#8211; as alluded to above &#8211; is focusing on:<br />
- Data shared between methods<br />
- The impact to the bject&#8217;s client/user of making a change.<br />
- Usage scenarios<br />
W/ respect to the &#8220;BankAccount&#8221; model: that 1st extreme case (all methods in a separate class) provides maximum isolation of the client from change, but results in loss of encapsulation because multiple classes are operating on the bank account. In the 2nd extreme case (all methods in 1 class), this solves the encapsulation problem, but potentially affects every single client using the system when things change.</p>
<p>We have to come up with &#8220;reasonable&#8221; solutions, so thinking about all 4 things (reasons to change, shared data, client impacts, usage scenarios) seems a more noteworthy voice of &#8220;reason&#8221;.  Applying these, you seem to end up not with separate &#8220;Withdrawl&#8221; and &#8220;Deposit&#8221; classes or a big &#8220;Bank&#8221; class (e.g. w/ &#8220;Deposit&#8221; method that also takes the account number), but 2 (parent-child) account classes that seems to reasonably satisfy SRP.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Chambers</title>
		<link>http://lostechies.com/seanchambers/2008/03/15/ptom-single-responsibility-principle/#comment-222</link>
		<dc:creator>Sean Chambers</dc:creator>
		<pubDate>Mon, 24 Mar 2008 23:07:16 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2008/03/15/ptom-single-responsibility-principle.aspx#comment-222</guid>
		<description>@dauchande i agree with you there. i see it as the same way. only pertaining to the business responsibilities of the class. So I agree with you there.</description>
		<content:encoded><![CDATA[<p>@dauchande i agree with you there. i see it as the same way. only pertaining to the business responsibilities of the class. So I agree with you there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dauchande</title>
		<link>http://lostechies.com/seanchambers/2008/03/15/ptom-single-responsibility-principle/#comment-221</link>
		<dc:creator>dauchande</dc:creator>
		<pubDate>Mon, 24 Mar 2008 19:47:26 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2008/03/15/ptom-single-responsibility-principle.aspx#comment-221</guid>
		<description>Huh, I see GetHashCode, ToString, Equals, etc in object to be aspects related to the identity of an object, so I don&#039;t think they come under the context of the SRP any more than logging or threading would.

I see SRP related to the &quot;business&quot; responsiblities of the class and not aspects of it&#039;s identity, information hiding mechanisms, or state management (such as serialization).  Although I can see an argument for using a momento to do serialization, but that&#039;s a limitation of the language (platform) and not the domain.

Now if the BankAccount class did something like saving to the database or managing transactions, then it would have more than one reason to change and I think that would fall under the SRP.

Well, my $0.02</description>
		<content:encoded><![CDATA[<p>Huh, I see GetHashCode, ToString, Equals, etc in object to be aspects related to the identity of an object, so I don&#8217;t think they come under the context of the SRP any more than logging or threading would.</p>
<p>I see SRP related to the &#8220;business&#8221; responsiblities of the class and not aspects of it&#8217;s identity, information hiding mechanisms, or state management (such as serialization).  Although I can see an argument for using a momento to do serialization, but that&#8217;s a limitation of the language (platform) and not the domain.</p>
<p>Now if the BankAccount class did something like saving to the database or managing transactions, then it would have more than one reason to change and I think that would fall under the SRP.</p>
<p>Well, my $0.02</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Jack</title>
		<link>http://lostechies.com/seanchambers/2008/03/15/ptom-single-responsibility-principle/#comment-220</link>
		<dc:creator>Colin Jack</dc:creator>
		<pubDate>Tue, 18 Mar 2008 18:26:24 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sean_chambers/archive/2008/03/15/ptom-single-responsibility-principle.aspx#comment-220</guid>
		<description>Interesting, I&#039;ve never seen the SRP that way before.

I guess though that this is really just handling implementation SRP because you&#039;ve separated the code (though into a subclass rather than a totally separate class) but you&#039;ve not got interface SRP. In this case that&#039;s fine but in a lot of cases I think you really need to break the behavior out completely.

Just in general my favourite descriptions of SRP comes in &quot;Working Effectively With Legacy Code&quot;, I particularly like the ScheduledJob example.</description>
		<content:encoded><![CDATA[<p>Interesting, I&#8217;ve never seen the SRP that way before.</p>
<p>I guess though that this is really just handling implementation SRP because you&#8217;ve separated the code (though into a subclass rather than a totally separate class) but you&#8217;ve not got interface SRP. In this case that&#8217;s fine but in a lot of cases I think you really need to break the behavior out completely.</p>
<p>Just in general my favourite descriptions of SRP comes in &#8220;Working Effectively With Legacy Code&#8221;, I particularly like the ScheduledJob example.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
