<?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: How to Think About the &#8220;new&#8221; Operator with Respect to Unit Testing</title>
	<atom:link href="http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/feed/" rel="self" type="application/rss+xml" />
	<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-think-about-the-new-operator</link>
	<description>Testability Explorer</description>
	<lastBuildDate>Thu, 19 Jan 2012 16:42:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Asbjørn</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-10242</link>
		<dc:creator>Asbjørn</dc:creator>
		<pubDate>Wed, 07 Sep 2011 12:45:17 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-10242</guid>
		<description>How about using a mock/stub tool that doesn&#039;t require DI?</description>
		<content:encoded><![CDATA[<p>How about using a mock/stub tool that doesn&#8217;t require DI?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-8688</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Sun, 05 Jun 2011 18:24:02 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-8688</guid>
		<description>@Morl99,

No, value objects do not need to be separate their news. More discussion here: http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/</description>
		<content:encoded><![CDATA[<p>@Morl99,</p>
<p>No, value objects do not need to be separate their news. More discussion here: <a href="http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/" rel="nofollow">http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morl99</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-8525</link>
		<dc:creator>Morl99</dc:creator>
		<pubDate>Tue, 31 May 2011 12:54:57 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-8525</guid>
		<description>@misko

just read all the blogposts about this topic. Great stuff, I really liked those and I hope I remember to send them to my friends!

I have a question though, do you believe, that the separation of Object Construction and Logic should even be valid for standard library Objects such as Collections? If I need a queue for storing incoming Messages, would it be a violation to your rules to write
messageQueue = new Queue( );
inside the Constructor of my Class?

I would really like to hear your opinion on that. I suspect, that it is the best way to handle this, because the Queue (or any other Standard Library Object) is completly tied to my Class, even when Unit Testing.

Keep it up!</description>
		<content:encoded><![CDATA[<p>@misko</p>
<p>just read all the blogposts about this topic. Great stuff, I really liked those and I hope I remember to send them to my friends!</p>
<p>I have a question though, do you believe, that the separation of Object Construction and Logic should even be valid for standard library Objects such as Collections? If I need a queue for storing incoming Messages, would it be a violation to your rules to write<br />
messageQueue = new Queue( );<br />
inside the Constructor of my Class?</p>
<p>I would really like to hear your opinion on that. I suspect, that it is the best way to handle this, because the Queue (or any other Standard Library Object) is completly tied to my Class, even when Unit Testing.</p>
<p>Keep it up!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-8027</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Thu, 05 May 2011 16:20:46 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-8027</guid>
		<description>@Oz,

The cost of DI is arguments is a myth of not taking DI to its extreme: http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/

What you have suggested at first looks like a good idea, and as long as you look at the class in isolation it is. The trouble becomes when you are testing house which needs kitchen. Since house will call the default constructor it is easy to cross the line and have the whole thing become the same as not having DI, so in practice this dose not work.</description>
		<content:encoded><![CDATA[<p>@Oz,</p>
<p>The cost of DI is arguments is a myth of not taking DI to its extreme: <a href="http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/" rel="nofollow">http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/</a></p>
<p>What you have suggested at first looks like a good idea, and as long as you look at the class in isolation it is. The trouble becomes when you are testing house which needs kitchen. Since house will call the default constructor it is easy to cross the line and have the whole thing become the same as not having DI, so in practice this dose not work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: OZ</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-7869</link>
		<dc:creator>OZ</dc:creator>
		<pubDate>Tue, 26 Apr 2011 13:31:12 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-7869</guid>
		<description>First: Thank you for your lessons, I become understand much more.

I agree, that DI is much more flexible way, but anything has it&#039;s cost, and cost of using DI is lot of passed arguments.

What if we will build class both flexible (able to be isolated) and self-enough?
My example will be in PHP, not Java, excuse me for this, but I hope syntax not so different:

class House
{
    private $kitchen;
    
    public function __construct(IKitchen $Kitchen = null)
    {
        if (empty($Kitchen)) $Kitchen = new BaseKitchen();
        else $this-&gt;kitchen = $Kitchen;
    }
}

this class can be created with empty constructor, which can be very handy in many situations, and it will be decrease count of not necessary initializations of Kitchen object in code.
In other hand, this object can be created with special version of Kitchen (e.g. mock-object) in tests.

Please, comment, what do you think about this variant.</description>
		<content:encoded><![CDATA[<p>First: Thank you for your lessons, I become understand much more.</p>
<p>I agree, that DI is much more flexible way, but anything has it&#8217;s cost, and cost of using DI is lot of passed arguments.</p>
<p>What if we will build class both flexible (able to be isolated) and self-enough?<br />
My example will be in PHP, not Java, excuse me for this, but I hope syntax not so different:</p>
<p>class House<br />
{<br />
    private $kitchen;</p>
<p>    public function __construct(IKitchen $Kitchen = null)<br />
    {<br />
        if (empty($Kitchen)) $Kitchen = new BaseKitchen();<br />
        else $this-&gt;kitchen = $Kitchen;<br />
    }<br />
}</p>
<p>this class can be created with empty constructor, which can be very handy in many situations, and it will be decrease count of not necessary initializations of Kitchen object in code.<br />
In other hand, this object can be created with special version of Kitchen (e.g. mock-object) in tests.</p>
<p>Please, comment, what do you think about this variant.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Objective-C: Frustrations of a Java Programmer &#124; richardrauser.com</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-3702</link>
		<dc:creator>Objective-C: Frustrations of a Java Programmer &#124; richardrauser.com</dc:creator>
		<pubDate>Wed, 07 Jul 2010 18:08:47 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-3702</guid>
		<description>[...] 9. Unit testing: OCUnit and OCMock are fairly immature compared to jUnit and jMock. And furthermore, a number of Cocoa classes include real work in their &#8220;constructors.&#8221; For instance, NSUrlConnection actually opens an HTTP connection and interacts online in its initWithRequest:delegate: method. The problem this creates is that object creation is tied to real work. This makes dependency injection difficult because we can&#8217;t separate the creation of the object from the logic, which would be required in order to substitute a test stub with test logic in its place. Dang. For more on this, see Misko Hevery&#8217;s great article on unit testing, object creation and logic. [...]</description>
		<content:encoded><![CDATA[<p>[...] 9. Unit testing: OCUnit and OCMock are fairly immature compared to jUnit and jMock. And furthermore, a number of Cocoa classes include real work in their &#8220;constructors.&#8221; For instance, NSUrlConnection actually opens an HTTP connection and interacts online in its initWithRequest:delegate: method. The problem this creates is that object creation is tied to real work. This makes dependency injection difficult because we can&#8217;t separate the creation of the object from the logic, which would be required in order to substitute a test stub with test logic in its place. Dang. For more on this, see Misko Hevery&#8217;s great article on unit testing, object creation and logic. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dependency Injection and Inversion of Control &#124; Geek on the Loose</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-3104</link>
		<dc:creator>Dependency Injection and Inversion of Control &#124; Geek on the Loose</dc:creator>
		<pubDate>Sun, 21 Feb 2010 00:50:45 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-3104</guid>
		<description>[...] Fowler: Inversion of Control Containers and the Dependency Injection pattern [5] Miško Hevery: How to Think About the &quot;new&quot; Operator with Respect to Unit Testing [6] Top 50 Linux Quotes of All Time, #10 [note lkml == Linux Kernel Mailing List] [7] Miško [...]</description>
		<content:encoded><![CDATA[<p>[...] Fowler: Inversion of Control Containers and the Dependency Injection pattern [5] Miško Hevery: How to Think About the &quot;new&quot; Operator with Respect to Unit Testing [6] Top 50 Linux Quotes of All Time, #10 [note lkml == Linux Kernel Mailing List] [7] Miško [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-1901</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Fri, 18 Sep 2009 15:53:11 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-1901</guid>
		<description>@Radek,

sure, if you are certain that they will always come together, than sure you can do that, but you will never be able to wire it differently. You can get away in few leafs sometimes with this strategy, but it should be rare, the default behavior should always me inject, unless you have a really good reason why it should be something different.</description>
		<content:encoded><![CDATA[<p>@Radek,</p>
<p>sure, if you are certain that they will always come together, than sure you can do that, but you will never be able to wire it differently. You can get away in few leafs sometimes with this strategy, but it should be rare, the default behavior should always me inject, unless you have a really good reason why it should be something different.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Radek</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-1900</link>
		<dc:creator>Radek</dc:creator>
		<pubDate>Fri, 18 Sep 2009 15:41:15 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-1900</guid>
		<description>But, you know, sometimes it just doesn&#039;t make sense to test a house with stubbed kitchen. :-) Let&#039;s say that we have only one, absolutely perfect (&quot;final class&quot;) kitchen. Then there&#039;s no need for DI and builders, kitchen is integral part of the house, and both the house and the kitchen should be treated like a black-box, single entity...</description>
		<content:encoded><![CDATA[<p>But, you know, sometimes it just doesn&#8217;t make sense to test a house with stubbed kitchen. <img src='http://misko.hevery.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Let&#8217;s say that we have only one, absolutely perfect (&#8220;final class&#8221;) kitchen. Then there&#8217;s no need for DI and builders, kitchen is integral part of the house, and both the house and the kitchen should be treated like a black-box, single entity&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Rauser</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-1889</link>
		<dc:creator>Richard Rauser</dc:creator>
		<pubDate>Thu, 17 Sep 2009 15:11:17 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-1889</guid>
		<description>Another great article among many from you, Misko. I&#039;m wondering what you would suggest when building an object graph that includes dependencies on 3rd party libraries that do themselves mix application logic with object creation. 

For instance:

private LocalDevice localDevice;

public BluetoothManager() throws BluetoothStateException {

        localDevice = LocalDevice.getLocalDevice();
       
}

Given that LocalDevice is not within my domain and .getLocalDevice() contains logic along with creation of a LocalDevice object, what would you do? Inject it into my BluetoothManager and introduce logic into my object graph builder, or perhaps move localDevice = LocalDevice.getLocalDevice() to an init() method  and agree to suffer creating a LocalDevice from within my business logic?</description>
		<content:encoded><![CDATA[<p>Another great article among many from you, Misko. I&#8217;m wondering what you would suggest when building an object graph that includes dependencies on 3rd party libraries that do themselves mix application logic with object creation. </p>
<p>For instance:</p>
<p>private LocalDevice localDevice;</p>
<p>public BluetoothManager() throws BluetoothStateException {</p>
<p>        localDevice = LocalDevice.getLocalDevice();</p>
<p>}</p>
<p>Given that LocalDevice is not within my domain and .getLocalDevice() contains logic along with creation of a LocalDevice object, what would you do? Inject it into my BluetoothManager and introduce logic into my object graph builder, or perhaps move localDevice = LocalDevice.getLocalDevice() to an init() method  and agree to suffer creating a LocalDevice from within my business logic?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

