<?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: Composition Of Responsibility vs Interface Implementation</title>
	<atom:link href="http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/</link>
	<description>Better Than Yesterday</description>
	<lastBuildDate>Fri, 24 May 2013 06:39: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: Derick Bailey</title>
		<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/#comment-2092</link>
		<dc:creator>Derick Bailey</dc:creator>
		<pubDate>Thu, 05 Jan 2012 21:19:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/derickbailey/?p=749#comment-2092</guid>
		<description>names are good because they give us shared meaning. but it&#039;s the meaning, and subtleties of the meaning that are really important.

&quot;responsibility&quot; is very subjective and too open to the overly analytical left-brain developers that want to over-engineer everything. &quot;I&#039;m building a car? Ok, it needs an engine. So I need pistons, crank shaft, oil pan / pump, spark plugs, block, ....&quot; vs &quot;I&#039;m building a car that accelerates and breaks? Ok. Here&#039;s the car w/ an accelerate method, and a break method.&quot;

&quot;one reason to change&quot; forces us to ask questions about the reasons for change... what are the valid reasons in this case. what are the possible vectors of change that we know of in this application? Am I building a vehicle repair system that needs to track every single part? Or am I building a child&#039;s entry-level video game with two buttons: accelerate and break?

... fwiw: i keep waiting for someone to come along and show me where my opinions and ideas have gone off the deep end. these are my opinions and ideas after having dealt with this stuff for a bunch of years... but i still don&#039;t think i&#039;m an &quot;expert&quot; with this stuff by any means. i keep going back to the examples used in the &quot;Agile principles, patterns and practices&quot; book, and scratching my head at how they came up with some of those examples and great solutions. :P</description>
		<content:encoded><![CDATA[<p>names are good because they give us shared meaning. but it&#8217;s the meaning, and subtleties of the meaning that are really important.</p>
<p>&#8220;responsibility&#8221; is very subjective and too open to the overly analytical left-brain developers that want to over-engineer everything. &#8220;I&#8217;m building a car? Ok, it needs an engine. So I need pistons, crank shaft, oil pan / pump, spark plugs, block, &#8230;.&#8221; vs &#8220;I&#8217;m building a car that accelerates and breaks? Ok. Here&#8217;s the car w/ an accelerate method, and a break method.&#8221;</p>
<p>&#8220;one reason to change&#8221; forces us to ask questions about the reasons for change&#8230; what are the valid reasons in this case. what are the possible vectors of change that we know of in this application? Am I building a vehicle repair system that needs to track every single part? Or am I building a child&#8217;s entry-level video game with two buttons: accelerate and break?</p>
<p>&#8230; fwiw: i keep waiting for someone to come along and show me where my opinions and ideas have gone off the deep end. these are my opinions and ideas after having dealt with this stuff for a bunch of years&#8230; but i still don&#8217;t think i&#8217;m an &#8220;expert&#8221; with this stuff by any means. i keep going back to the examples used in the &#8220;Agile principles, patterns and practices&#8221; book, and scratching my head at how they came up with some of those examples and great solutions. :P</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Murray</title>
		<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/#comment-2090</link>
		<dc:creator>Mike Murray</dc:creator>
		<pubDate>Thu, 05 Jan 2012 07:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/derickbailey/?p=749#comment-2090</guid>
		<description>Yeah, ok...not much I disagree with there...

I guess I still don&#039;t see the distinction between roles and responsibilities as you are seeing it. Can you elaborate on situations where an object would keep to a single responsibility but take on multiple roles?

I&#039;m also sensing you making a separation between the name of the principle and its definition? Are you saying that taking the name of the principle (&quot;single responsibility&quot;) too literally is an unnecessary restriction, and that following the definition of the principle (&quot;one reason to change&quot;) is sufficient? Isn&#039;t having more than one role having more than one reason to change?

Interested to hear your thoughts. Thanks!</description>
		<content:encoded><![CDATA[<p>Yeah, ok&#8230;not much I disagree with there&#8230;</p>
<p>I guess I still don&#8217;t see the distinction between roles and responsibilities as you are seeing it. Can you elaborate on situations where an object would keep to a single responsibility but take on multiple roles?</p>
<p>I&#8217;m also sensing you making a separation between the name of the principle and its definition? Are you saying that taking the name of the principle (&#8220;single responsibility&#8221;) too literally is an unnecessary restriction, and that following the definition of the principle (&#8220;one reason to change&#8221;) is sufficient? Isn&#8217;t having more than one role having more than one reason to change?</p>
<p>Interested to hear your thoughts. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derick Bailey</title>
		<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/#comment-2089</link>
		<dc:creator>Derick Bailey</dc:creator>
		<pubDate>Wed, 04 Jan 2012 18:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/derickbailey/?p=749#comment-2089</guid>
		<description>Having an object take on multiple roles is not an SRP violation in itself. It&#039;s the single Responsibility principles, not single Role principle.

SRP says a class (or object in non-classy languages) should have one reason to change. We change a class/object by changing it&#039;s code. If I define 5 or 10 fields for my Foo class in the above example, and use it in a simple forms over data app, there&#039;s likely no violation of SRP happening because the responsibility of the class is moving data between the form/user input and the database.

That doesn&#039;t mean it&#039;s never an SRP violation, though. SRP is very contextually sensitive. An SRP violation in one code base may be a perfectly fine chunk of code with no SRP violation in another context.

If I&#039;m building a highly complex business application with tendencies toward domain modeling and other domain-driven-design concepts, then including Mongoid::Document in a domain model is likely an SRP violation... not because there are too many methods on the runtime object, though. But because I have chosen to mix the responsibility of data persistence with the responsibility of the domain model.

For more of my opinion on SRP, see my SOLID article here: http://www.code-magazine.com/article.aspx?quickid=1001061&amp;page=4</description>
		<content:encoded><![CDATA[<p>Having an object take on multiple roles is not an SRP violation in itself. It&#8217;s the single Responsibility principles, not single Role principle.</p>
<p>SRP says a class (or object in non-classy languages) should have one reason to change. We change a class/object by changing it&#8217;s code. If I define 5 or 10 fields for my Foo class in the above example, and use it in a simple forms over data app, there&#8217;s likely no violation of SRP happening because the responsibility of the class is moving data between the form/user input and the database.</p>
<p>That doesn&#8217;t mean it&#8217;s never an SRP violation, though. SRP is very contextually sensitive. An SRP violation in one code base may be a perfectly fine chunk of code with no SRP violation in another context.</p>
<p>If I&#8217;m building a highly complex business application with tendencies toward domain modeling and other domain-driven-design concepts, then including Mongoid::Document in a domain model is likely an SRP violation&#8230; not because there are too many methods on the runtime object, though. But because I have chosen to mix the responsibility of data persistence with the responsibility of the domain model.</p>
<p>For more of my opinion on SRP, see my SOLID article here: http://www.code-magazine.com/article.aspx?quickid=1001061&amp;page=4</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Murray</title>
		<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/#comment-2088</link>
		<dc:creator>Mike Murray</dc:creator>
		<pubDate>Wed, 04 Jan 2012 17:04:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/derickbailey/?p=749#comment-2088</guid>
		<description>So I can understand the argument to focus on roles/responsibilities instead of 1-to-1 interfaces. But at what point are you not following SRP by having your objects take on too many roles?</description>
		<content:encoded><![CDATA[<p>So I can understand the argument to focus on roles/responsibilities instead of 1-to-1 interfaces. But at what point are you not following SRP by having your objects take on too many roles?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derick Bailey</title>
		<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/#comment-2086</link>
		<dc:creator>Derick Bailey</dc:creator>
		<pubDate>Wed, 04 Jan 2012 00:58:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/derickbailey/?p=749#comment-2086</guid>
		<description>In general: I read the code and the documentation for the code. 

The problem with heavy use of mixins, from the perspective of what functions are for what responsibility, is generally at runtime. doing a list of methods like i did is a runtime call, for example. but the actual code for Mongoid, and the documentation for it, are not a giant blob like that. 

If you look at Ruby&#039;s Array class documentation (which is admittedly a poor example because of the number of methods on it) you can see that it includes the Enumerable module. 

http://ruby-doc.org/core-1.9.3/Array.html

Assuming I know what an Enumerable is, in Ruby, and have a fair idea of what responsibilities that module encompasses, I now know one of the responsibilities that is mixed in to an Array. 

Knowing that an Enumerable exists allows me to write code to that API/Protocol/whatever you want to call it. When I&#039;m writing my own code or reading documentation for other people&#039;s code and I see someone say that a parameter should be an Enumerable, I have knowledge of what that is because the documentation has lead me to it.</description>
		<content:encoded><![CDATA[<p>In general: I read the code and the documentation for the code. </p>
<p>The problem with heavy use of mixins, from the perspective of what functions are for what responsibility, is generally at runtime. doing a list of methods like i did is a runtime call, for example. but the actual code for Mongoid, and the documentation for it, are not a giant blob like that. </p>
<p>If you look at Ruby&#8217;s Array class documentation (which is admittedly a poor example because of the number of methods on it) you can see that it includes the Enumerable module. </p>
<p><a href="http://ruby-doc.org/core-1.9.3/Array.html" rel="nofollow">http://ruby-doc.org/core-1.9.3/Array.html</a></p>
<p>Assuming I know what an Enumerable is, in Ruby, and have a fair idea of what responsibilities that module encompasses, I now know one of the responsibilities that is mixed in to an Array. </p>
<p>Knowing that an Enumerable exists allows me to write code to that API/Protocol/whatever you want to call it. When I&#8217;m writing my own code or reading documentation for other people&#8217;s code and I see someone say that a parameter should be an Enumerable, I have knowledge of what that is because the documentation has lead me to it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/#comment-2084</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 03 Jan 2012 22:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/derickbailey/?p=749#comment-2084</guid>
		<description>I would personally like to hear more about:

 &quot;If we look at a message-based method dispatch in the same light and perspective as we do a interface-based dispatch, things look bad. If we look at the message-based, first-class-mixin system as a series of responsibilities, though, with each responsibility having it’s own protocol definition and each responsibility and protocol captured into an object that can be composed into a larger piece (again, mixins), things look much better.&quot;

How do you look at and understand highly mixed code, protocol definition at the ruby method / message level - etc.</description>
		<content:encoded><![CDATA[<p>I would personally like to hear more about:</p>
<p> &#8221;If we look at a message-based method dispatch in the same light and perspective as we do a interface-based dispatch, things look bad. If we look at the message-based, first-class-mixin system as a series of responsibilities, though, with each responsibility having it’s own protocol definition and each responsibility and protocol captured into an object that can be composed into a larger piece (again, mixins), things look much better.&#8221;</p>
<p>How do you look at and understand highly mixed code, protocol definition at the ruby method / message level &#8211; etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/#comment-2085</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 03 Jan 2012 22:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/derickbailey/?p=749#comment-2085</guid>
		<description>links would work too. :)</description>
		<content:encoded><![CDATA[<p>links would work too. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Jack</title>
		<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/#comment-2083</link>
		<dc:creator>Colin Jack</dc:creator>
		<pubDate>Tue, 03 Jan 2012 17:03:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/derickbailey/?p=749#comment-2083</guid>
		<description>&quot;When I list the methods for a Foo instance at runtime, though, that&#039;s a 
different story. the ability to compose objects at run time means we 
can&#039;t assume the same perspective on what these principles look like at 
runtime.&quot;


Definitely, I maybe wasn&#039;t clear. Lets say I&#039;m coming to a new method and its taking in an argument. I just want a quick summary of what I can do with that argument. You&#039;ve answered how to work it out, and I do the same, look at code or documentation (or tests). 

But just compare static to dynamic here. Static if I&#039;ve used ISP I know exactly what I can do with the argument, the protocol is explicit. Dynamic I obviously can&#039;t be 100% sure (metaprogramming) but even ignoring that its a bit more implicit. Thats good if I get to a type somehow (say Foo) but less good if Foo has lots of mixins, suddenly I have a lot of choices (lots of responsibilities in one place). I&#039;ve got a bit of work to find out which of them applies in this context.

This is not an argument against dynamic languages at all, but I do worry that if you have such a wide interface combined with a dynamic language then you could be making it hard for the maintainers of your code.

Caveat is this hasn&#039;t been a big problem for me, but then I haven&#039;t actually worked on large Ruby codebases and I have found it to be a little bit of an issue when working with some open source Ruby code.




</description>
		<content:encoded><![CDATA[<p>&#8220;When I list the methods for a Foo instance at runtime, though, that&#8217;s a<br />
different story. the ability to compose objects at run time means we<br />
can&#8217;t assume the same perspective on what these principles look like at<br />
runtime.&#8221;</p>
<p>Definitely, I maybe wasn&#8217;t clear. Lets say I&#8217;m coming to a new method and its taking in an argument. I just want a quick summary of what I can do with that argument. You&#8217;ve answered how to work it out, and I do the same, look at code or documentation (or tests). </p>
<p>But just compare static to dynamic here. Static if I&#8217;ve used ISP I know exactly what I can do with the argument, the protocol is explicit. Dynamic I obviously can&#8217;t be 100% sure (metaprogramming) but even ignoring that its a bit more implicit. Thats good if I get to a type somehow (say Foo) but less good if Foo has lots of mixins, suddenly I have a lot of choices (lots of responsibilities in one place). I&#8217;ve got a bit of work to find out which of them applies in this context.</p>
<p>This is not an argument against dynamic languages at all, but I do worry that if you have such a wide interface combined with a dynamic language then you could be making it hard for the maintainers of your code.</p>
<p>Caveat is this hasn&#8217;t been a big problem for me, but then I haven&#8217;t actually worked on large Ruby codebases and I have found it to be a little bit of an issue when working with some open source Ruby code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derick Bailey</title>
		<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/#comment-2082</link>
		<dc:creator>Derick Bailey</dc:creator>
		<pubDate>Tue, 03 Jan 2012 16:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/derickbailey/?p=749#comment-2082</guid>
		<description>354 methods would be horrible to sift through if i ever looked at that list with intellisense or via command line as shown above. i very rarely do this, though. i use vim and i never use the auto-complete (intellisense-like) feature. 

the only time i ever list the methods on an object are when i think there should be a method with a specific name... then i&#039;ll `.methods.grep(/name/)` to find it. other than that, i read documentation for each of the separate responsibilities, and I look at the code to find the responsibilities and the protocols (API) that they implement.

as for ISP... i&#039;m not sure ISP as it was originally defined applies to ruby very well. Jim Weirich discussed SOLID ruby back in 2009: http://confreaks.net/videos/185-rubyconf2009-solid-ruby note in the ISP section (at 40:10), he all but says that ISP doesn&#039;t apply because a language like ruby requires a far deeper implementation of DIP - dependency inversion - via responsibilities and protocols (APIs). he specifically says &quot;depend upon narrow protocols&quot;, but in his description of that he talks about dependency inversion. 

with such a deep need for dependency inversion, the ability to easy mix a dependency&#039;s protocol into an object, and the nature of ruby being message-based dispatch instead of interface-based, I have a hard time seeing classic ISP techniques as a concern. ISP itself still applies... but i don&#039;t think it&#039;s a first-class concern in Ruby. i think it&#039;s a side effect of other principles, like DIP, SRP, etc. 

when looking at the code and documentation for my Foo object, I should see the API that directly relates to Foo and it should be simple and ISP conforming. When I list the methods for a Foo instance at runtime, though, that&#039;s a different story. the ability to compose objects at run time means we can&#039;t assume the same perspective on what these principles look like at runtime.

</description>
		<content:encoded><![CDATA[<p>354 methods would be horrible to sift through if i ever looked at that list with intellisense or via command line as shown above. i very rarely do this, though. i use vim and i never use the auto-complete (intellisense-like) feature. </p>
<p>the only time i ever list the methods on an object are when i think there should be a method with a specific name&#8230; then i&#8217;ll `.methods.grep(/name/)` to find it. other than that, i read documentation for each of the separate responsibilities, and I look at the code to find the responsibilities and the protocols (API) that they implement.</p>
<p>as for ISP&#8230; i&#8217;m not sure ISP as it was originally defined applies to ruby very well. Jim Weirich discussed SOLID ruby back in 2009: http://confreaks.net/videos/185-rubyconf2009-solid-ruby note in the ISP section (at 40:10), he all but says that ISP doesn&#8217;t apply because a language like ruby requires a far deeper implementation of DIP &#8211; dependency inversion &#8211; via responsibilities and protocols (APIs). he specifically says &#8220;depend upon narrow protocols&#8221;, but in his description of that he talks about dependency inversion. </p>
<p>with such a deep need for dependency inversion, the ability to easy mix a dependency&#8217;s protocol into an object, and the nature of ruby being message-based dispatch instead of interface-based, I have a hard time seeing classic ISP techniques as a concern. ISP itself still applies&#8230; but i don&#8217;t think it&#8217;s a first-class concern in Ruby. i think it&#8217;s a side effect of other principles, like DIP, SRP, etc. </p>
<p>when looking at the code and documentation for my Foo object, I should see the API that directly relates to Foo and it should be simple and ISP conforming. When I list the methods for a Foo instance at runtime, though, that&#8217;s a different story. the ability to compose objects at run time means we can&#8217;t assume the same perspective on what these principles look like at runtime.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Jack</title>
		<link>http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/#comment-2081</link>
		<dc:creator>Colin Jack</dc:creator>
		<pubDate>Tue, 03 Jan 2012 15:54:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/derickbailey/?p=749#comment-2081</guid>
		<description>&quot;Yes, my “Foo” object in the above example still has 354 methods on it. 
But how many of these do you really care about for a given scenario?&quot;

I get what your saying but when faced with an object with 354 methods don&#039;t you end up being a bit lost?

To me thats where the interface segregation principle has value, it makes it much easier (as a developer) to reason about a particular object. Mixins help with that to some extent, its not like you look at your type and see 354 methods, but the roles you mention are pretty implicit when your looking at a particular object (or argument). 

I am looking forward to giving Dart a proper run for its money because to me its optional typing could have real possibilities, for example in the case of your Foo maybe carving off some of that behavior into an interface so that when viewing the code one of the responsibilities is made more concrete.</description>
		<content:encoded><![CDATA[<p>&#8220;Yes, my “Foo” object in the above example still has 354 methods on it.<br />
But how many of these do you really care about for a given scenario?&#8221;</p>
<p>I get what your saying but when faced with an object with 354 methods don&#8217;t you end up being a bit lost?</p>
<p>To me thats where the interface segregation principle has value, it makes it much easier (as a developer) to reason about a particular object. Mixins help with that to some extent, its not like you look at your type and see 354 methods, but the roles you mention are pretty implicit when your looking at a particular object (or argument). </p>
<p>I am looking forward to giving Dart a proper run for its money because to me its optional typing could have real possibilities, for example in the case of your Foo maybe carving off some of that behavior into an interface so that when viewing the code one of the responsibilities is made more concrete.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
