<?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"
	>
<channel>
	<title>Comments on: Embracing Change</title>
	<atom:link href="http://kohari.org/2007/08/21/embracing-change/feed/" rel="self" type="application/rss+xml" />
	<link>http://kohari.org/2007/08/21/embracing-change/</link>
	<description>Organized chaos</description>
	<pubDate>Fri, 05 Dec 2008 09:23:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Yoni</title>
		<link>http://kohari.org/2007/08/21/embracing-change/#comment-57</link>
		<dc:creator>Yoni</dc:creator>
		<pubDate>Fri, 24 Aug 2007 08:48:02 +0000</pubDate>
		<guid isPermaLink="false">http://kohari.org/2007/08/21/embracing-change/#comment-57</guid>
		<description>Well all I can tell you is that even though I'm doing all my DI by hand I never got to the point of having more than "new A(new B(new C()))" - which, actually, does not couple A to C but rather couples the code which constructs A to B and C (an important difference). The reason is not that I don't have more layers of dependencies but rather that the object creation process itself is divided among objects. Meaning there is usually only "new A(b)" where b was constructed earlier and is accessible to the current context. This control over the way objects are created allows for simple scenarios to be handled with a few lines of code (which is shorter than configuring the DI container), and complex scenarios to be handled with all the power of OOP (which will always be more flexible and easier to debug than the DI container).

The singleton feature is nice but I rarely use singletons so that doesn't help either :). And again, controlling object creation in code gives you a lot more control over the service's lifecycle...

Regarding interface-based development I wasn't asking a question but rather offering advice. The problem of interfaces with single implementations being YAGNI can easily be solved by only allowing service's with two or more implementations. But I guess this should probably wait for another discussion.</description>
		<content:encoded><![CDATA[<p>Well all I can tell you is that even though I&#8217;m doing all my DI by hand I never got to the point of having more than &#8220;new A(new B(new C()))&#8221; - which, actually, does not couple A to C but rather couples the code which constructs A to B and C (an important difference). The reason is not that I don&#8217;t have more layers of dependencies but rather that the object creation process itself is divided among objects. Meaning there is usually only &#8220;new A(b)&#8221; where b was constructed earlier and is accessible to the current context. This control over the way objects are created allows for simple scenarios to be handled with a few lines of code (which is shorter than configuring the DI container), and complex scenarios to be handled with all the power of OOP (which will always be more flexible and easier to debug than the DI container).</p>
<p>The singleton feature is nice but I rarely use singletons so that doesn&#8217;t help either :). And again, controlling object creation in code gives you a lot more control over the service&#8217;s lifecycle&#8230;</p>
<p>Regarding interface-based development I wasn&#8217;t asking a question but rather offering advice. The problem of interfaces with single implementations being YAGNI can easily be solved by only allowing service&#8217;s with two or more implementations. But I guess this should probably wait for another discussion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nate Kohari</title>
		<link>http://kohari.org/2007/08/21/embracing-change/#comment-59</link>
		<dc:creator>Nate Kohari</dc:creator>
		<pubDate>Fri, 24 Aug 2007 00:21:36 +0000</pubDate>
		<guid isPermaLink="false">http://kohari.org/2007/08/21/embracing-change/#comment-59</guid>
		<description>First off, there's nothing wrong with dependency injection by hand when you just have a single layer of dependencies. Things start to get really tough, really fast when you add layers. For example, here's what happens when you add a single layer of dependencies (rather than A-&gt;B, you're going A-&gt;B-&gt;C):

class A
{
  B _b;
  public A(B b) { _b = b; }
}

class B
{
  C _c;
  public B(C c) { _c = c; }
}

class C { ... }

To create an A, you have to chain up these dependencies:

A myA = new A(new B(new C()));

And remember, we've only added a single layer of dependencies... this is still an overly simplistic scenario that you wouldn't see in most real-world applications. More realistic services have multiple dependencies, circular relationships, etc, which are very difficult to manage by hand. It's not that you &lt;b&gt;can't&lt;/b&gt; do it, it's that it's much, much more difficult without a framework to help.

This also means that whatever code you're creating A in needs to know of the existence of not only the dependencies of A (in this case, B) -- but also the dependencies of A's dependencies (in this case, C). That means that A is now coupled to C, and so is any code that consumes A.  This can quickly expand exponentially in larger systems. You could easily get to the situation where every service in your system must be aware of every other service. Blech.

You're also ignoring another major benefit of DI frameworks: the ability to control a service's lifecycle. For example, with Ninject (and Windsor and Guice too), you can create a singleton simply by decorating your class definition with a [Singleton] attribute. To implement a singleton by hand, you either have to rely on something like a static Instance property, or a factory... neither of which is cleaner than a simple attribute. :)

I'm not sure I understand your question about interface-based development. Generally, I declare an actual interface to help me determine how a given service will interact with the rest of the application. That's why I feel they're useful even if you never end up defining more than one concrete implementation of the interface.</description>
		<content:encoded><![CDATA[<p>First off, there&#8217;s nothing wrong with dependency injection by hand when you just have a single layer of dependencies. Things start to get really tough, really fast when you add layers. For example, here&#8217;s what happens when you add a single layer of dependencies (rather than A->B, you&#8217;re going A->B->C):</p>
<p>class A<br />
{<br />
  B _b;<br />
  public A(B b) { _b = b; }<br />
}</p>
<p>class B<br />
{<br />
  C _c;<br />
  public B(C c) { _c = c; }<br />
}</p>
<p>class C { &#8230; }</p>
<p>To create an A, you have to chain up these dependencies:</p>
<p>A myA = new A(new B(new C()));</p>
<p>And remember, we&#8217;ve only added a single layer of dependencies&#8230; this is still an overly simplistic scenario that you wouldn&#8217;t see in most real-world applications. More realistic services have multiple dependencies, circular relationships, etc, which are very difficult to manage by hand. It&#8217;s not that you <b>can&#8217;t</b> do it, it&#8217;s that it&#8217;s much, much more difficult without a framework to help.</p>
<p>This also means that whatever code you&#8217;re creating A in needs to know of the existence of not only the dependencies of A (in this case, B) &#8212; but also the dependencies of A&#8217;s dependencies (in this case, C). That means that A is now coupled to C, and so is any code that consumes A.  This can quickly expand exponentially in larger systems. You could easily get to the situation where every service in your system must be aware of every other service. Blech.</p>
<p>You&#8217;re also ignoring another major benefit of DI frameworks: the ability to control a service&#8217;s lifecycle. For example, with Ninject (and Windsor and Guice too), you can create a singleton simply by decorating your class definition with a [Singleton] attribute. To implement a singleton by hand, you either have to rely on something like a static Instance property, or a factory&#8230; neither of which is cleaner than a simple attribute. :)</p>
<p>I&#8217;m not sure I understand your question about interface-based development. Generally, I declare an actual interface to help me determine how a given service will interact with the rest of the application. That&#8217;s why I feel they&#8217;re useful even if you never end up defining more than one concrete implementation of the interface.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yoni</title>
		<link>http://kohari.org/2007/08/21/embracing-change/#comment-58</link>
		<dc:creator>Yoni</dc:creator>
		<pubDate>Thu, 23 Aug 2007 23:42:51 +0000</pubDate>
		<guid isPermaLink="false">http://kohari.org/2007/08/21/embracing-change/#comment-58</guid>
		<description>"by exposing the dependencies of a type, you can actually increase your coupling, because you’re requiring that any code that consumes your type also has knowledge of the type’s dependencies"

Can you provide a code sample to explain this statement? The way I see it an object should usually accept a type - which encapsulates its external dependencies - at construction. For example:

class A
{
B _b;
public A(B b)
{
_b = b;
}
}

Now the code that constructs A is simply required to have an instance of B available at the time of construction. This is simple OOP and I don't see why it shouldn't scale...

Regarding the issue of the interfaces, why not simply follow this rule:
Dependencies should always be interfaces with at least two concrete implementations.

If your dependencies are interfaces which have only one concrete implementation how can you tell you've got the correct separation between the client and the service?</description>
		<content:encoded><![CDATA[<p>&#8220;by exposing the dependencies of a type, you can actually increase your coupling, because you’re requiring that any code that consumes your type also has knowledge of the type’s dependencies&#8221;</p>
<p>Can you provide a code sample to explain this statement? The way I see it an object should usually accept a type - which encapsulates its external dependencies - at construction. For example:</p>
<p>class A<br />
{<br />
B _b;<br />
public A(B b)<br />
{<br />
_b = b;<br />
}<br />
}</p>
<p>Now the code that constructs A is simply required to have an instance of B available at the time of construction. This is simple OOP and I don&#8217;t see why it shouldn&#8217;t scale&#8230;</p>
<p>Regarding the issue of the interfaces, why not simply follow this rule:<br />
Dependencies should always be interfaces with at least two concrete implementations.</p>
<p>If your dependencies are interfaces which have only one concrete implementation how can you tell you&#8217;ve got the correct separation between the client and the service?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
