<?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: Less interface intensive dependency injection (C#)</title>
	<atom:link href="http://blog.robbowley.net/2010/01/19/less-interface-intensive-dependency-injection-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.robbowley.net/2010/01/19/less-interface-intensive-dependency-injection-c/</link>
	<description>adventures in extreme programming</description>
	<lastBuildDate>Thu, 15 Jul 2010 11:34:19 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jason Gorman</title>
		<link>http://blog.robbowley.net/2010/01/19/less-interface-intensive-dependency-injection-c/comment-page-1/#comment-9927</link>
		<dc:creator>Jason Gorman</dc:creator>
		<pubDate>Sat, 13 Feb 2010 08:39:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.robbowley.net/?p=1118#comment-9927</guid>
		<description>I&#039;m getting C++ function pointer flashbacks. Seriously, don&#039;t go there! 

The goal is substitutability and the safe OO mechanism for that is polymorphism, not delegates! I think it&#039;s true that applying IoC ubiquitously as a design philosophy (which it isn&#039;t) rather than as a design patterm designed to solve a specific kind of problem is what leads to having too many interfaces. That these interfaces are &quot;anaemic&quot; isn&#039;t a problem. We should present small, client-specific interfaces (See &quot;Interface Segregation Principle&quot;). That there are too many interfaces? Well, code riddled with delegates would have me reaching for the gin first, I think. Been there. Done that. Never again! :-)

The only effective way to manage the dependencies in your code is to consider tham on a case-by-case basis. Declaring interfaces (or delegates) for every client-supplier relationship is not the way forward. It is OKAY to have clusters off closely-related concrete classes wich are packaged together talking directly to each other. It is OKAY to pass instances of concrete types into methods and constructors as long as this is a one-to-one relationship. If A depends on B and we&#039;re not crossing component or system boundaries, then that&#039;s probably fine. If A, B and C all depend on D then I think there&#039;s a real case for having a substitutible abstraction for D which they can bind to. I call it the &quot;Reused Abstractions&quot; design principle. And, of course, if there are specialisations of D then it&#039;s a no-brainer. But if there&#039;s just D and an interface ID and only A uses it, then something&#039;s amiss in your design. That&#039;s where this explosion of small interfaces often comes from - people routinely decalring interfaces that participate in only one relationship and are implemented only once. Mocking frameworks and IoC containers have a lot to answer for in that respect.</description>
		<content:encoded><![CDATA[<p>I&#8217;m getting C++ function pointer flashbacks. Seriously, don&#8217;t go there! </p>
<p>The goal is substitutability and the safe OO mechanism for that is polymorphism, not delegates! I think it&#8217;s true that applying IoC ubiquitously as a design philosophy (which it isn&#8217;t) rather than as a design patterm designed to solve a specific kind of problem is what leads to having too many interfaces. That these interfaces are &#8220;anaemic&#8221; isn&#8217;t a problem. We should present small, client-specific interfaces (See &#8220;Interface Segregation Principle&#8221;). That there are too many interfaces? Well, code riddled with delegates would have me reaching for the gin first, I think. Been there. Done that. Never again! <img src='http://blog.robbowley.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The only effective way to manage the dependencies in your code is to consider tham on a case-by-case basis. Declaring interfaces (or delegates) for every client-supplier relationship is not the way forward. It is OKAY to have clusters off closely-related concrete classes wich are packaged together talking directly to each other. It is OKAY to pass instances of concrete types into methods and constructors as long as this is a one-to-one relationship. If A depends on B and we&#8217;re not crossing component or system boundaries, then that&#8217;s probably fine. If A, B and C all depend on D then I think there&#8217;s a real case for having a substitutible abstraction for D which they can bind to. I call it the &#8220;Reused Abstractions&#8221; design principle. And, of course, if there are specialisations of D then it&#8217;s a no-brainer. But if there&#8217;s just D and an interface ID and only A uses it, then something&#8217;s amiss in your design. That&#8217;s where this explosion of small interfaces often comes from &#8211; people routinely decalring interfaces that participate in only one relationship and are implemented only once. Mocking frameworks and IoC containers have a lot to answer for in that respect.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Fernandes</title>
		<link>http://blog.robbowley.net/2010/01/19/less-interface-intensive-dependency-injection-c/comment-page-1/#comment-9126</link>
		<dc:creator>Daniel Fernandes</dc:creator>
		<pubDate>Wed, 20 Jan 2010 10:27:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.robbowley.net/?p=1118#comment-9126</guid>
		<description>Rob

I don&#039;t think it&#039;s a straw man argument.
Say you have &quot;int ICounter.Next()&quot; and &quot;int IClock.Minutes {get;}&quot;

Both of these interfaces could be replaced with Func if you wanted to.

If in my code I have a dependency on Func, I&#039;d have to check where it&#039;s declared to know what it means, .Net allows you to create lambda expressions therefore inlining implementation of say Func.

So to me, swapping from single method interfaces to delegates might be removing noise but you&#039;re adding confusion to your codebase and not only that you no longer do static code analysis if that&#039;s what you like doing.


I am personally keener on creating interfaces that provide a set of cohesive operations, unlike the tendency of creating single usage interfaces so I can see where you&#039;re coming from.

Daniel</description>
		<content:encoded><![CDATA[<p>Rob</p>
<p>I don&#8217;t think it&#8217;s a straw man argument.<br />
Say you have &#8220;int ICounter.Next()&#8221; and &#8220;int IClock.Minutes {get;}&#8221;</p>
<p>Both of these interfaces could be replaced with Func if you wanted to.</p>
<p>If in my code I have a dependency on Func, I&#8217;d have to check where it&#8217;s declared to know what it means, .Net allows you to create lambda expressions therefore inlining implementation of say Func.</p>
<p>So to me, swapping from single method interfaces to delegates might be removing noise but you&#8217;re adding confusion to your codebase and not only that you no longer do static code analysis if that&#8217;s what you like doing.</p>
<p>I am personally keener on creating interfaces that provide a set of cohesive operations, unlike the tendency of creating single usage interfaces so I can see where you&#8217;re coming from.</p>
<p>Daniel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rob</title>
		<link>http://blog.robbowley.net/2010/01/19/less-interface-intensive-dependency-injection-c/comment-page-1/#comment-9123</link>
		<dc:creator>rob</dc:creator>
		<pubDate>Wed, 20 Jan 2010 09:32:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.robbowley.net/?p=1118#comment-9123</guid>
		<description>Hi Daniel,

This feels like a bit of a straw man argument to me. This approach is all about balancing the signal to noise ratio in your code. Use it when it removes noise but don&#039;t do if it adds to it.</description>
		<content:encoded><![CDATA[<p>Hi Daniel,</p>
<p>This feels like a bit of a straw man argument to me. This approach is all about balancing the signal to noise ratio in your code. Use it when it removes noise but don&#8217;t do if it adds to it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Fernandes</title>
		<link>http://blog.robbowley.net/2010/01/19/less-interface-intensive-dependency-injection-c/comment-page-1/#comment-9106</link>
		<dc:creator>Daniel Fernandes</dc:creator>
		<pubDate>Tue, 19 Jan 2010 22:30:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.robbowley.net/?p=1118#comment-9106</guid>
		<description>Fact : Using IoCs can indeed lead to an explosion of simple, single method being the more extreme case, interfaces, leading to very little overall cohesion within the code base. I see that happening every day at work.

Fact : Sometimes we don&#039;t have the time to design interfaces (or other types for that matter) that have a rich API. I guess we only care with the problem in hand at the moment and using IoCs and using TDD/BDD can lead to the situation you&#039;ve described. Would a TDD/BDD practicioner think that once the result has been achieved that maybe there is code reuse somewhere or enough similarility that it&#039;s worth introducing new abstractions to bring it all together ?

Fact : A lot of systems are built upon rather ceremonious bits. We have our UI, we have maybe our Queries or Commands, we have our Service Layers, we have our Domain and we may have some more, too. Sometimes, none of these layers ever modify data that might come from a layer down that need to go up the layer hierarchy. A lot of systems are built like that and they, I think, end up having a lot of small interfaces that will be implemented by stateless types.


Now, I&#039;d say your solution to substitute interfaces with delegates (Func, Action and all their variants apply) is horrible. A delegate is only defined by its type and the very nature of what .Net 3+ offers now we can create a delegate using generics which means we don&#039;t ever have a delegate type we could add metadata (like documentation), so there is nothing in hell somebody would know that such Action is a counter and the other Action returns the the current hour. 
I know a guy at work tried to push for that but we resisted, I think using a delegate within a set of closely related classes is perfectly valid solution though.

What you&#039;ve raised is I don&#039;t think a direct side-effect of using IoCs, just a side-effect of not refactoring code to promote code readibility/reuse in a system.


Daniel</description>
		<content:encoded><![CDATA[<p>Fact : Using IoCs can indeed lead to an explosion of simple, single method being the more extreme case, interfaces, leading to very little overall cohesion within the code base. I see that happening every day at work.</p>
<p>Fact : Sometimes we don&#8217;t have the time to design interfaces (or other types for that matter) that have a rich API. I guess we only care with the problem in hand at the moment and using IoCs and using TDD/BDD can lead to the situation you&#8217;ve described. Would a TDD/BDD practicioner think that once the result has been achieved that maybe there is code reuse somewhere or enough similarility that it&#8217;s worth introducing new abstractions to bring it all together ?</p>
<p>Fact : A lot of systems are built upon rather ceremonious bits. We have our UI, we have maybe our Queries or Commands, we have our Service Layers, we have our Domain and we may have some more, too. Sometimes, none of these layers ever modify data that might come from a layer down that need to go up the layer hierarchy. A lot of systems are built like that and they, I think, end up having a lot of small interfaces that will be implemented by stateless types.</p>
<p>Now, I&#8217;d say your solution to substitute interfaces with delegates (Func, Action and all their variants apply) is horrible. A delegate is only defined by its type and the very nature of what .Net 3+ offers now we can create a delegate using generics which means we don&#8217;t ever have a delegate type we could add metadata (like documentation), so there is nothing in hell somebody would know that such Action is a counter and the other Action returns the the current hour.<br />
I know a guy at work tried to push for that but we resisted, I think using a delegate within a set of closely related classes is perfectly valid solution though.</p>
<p>What you&#8217;ve raised is I don&#8217;t think a direct side-effect of using IoCs, just a side-effect of not refactoring code to promote code readibility/reuse in a system.</p>
<p>Daniel</p>
]]></content:encoded>
	</item>
</channel>
</rss>
