<?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/</link>
	<description>Testability Explorer</description>
	<lastBuildDate>Thu, 02 Sep 2010 04:05:01 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<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 (&#8221;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>
	<item>
		<title>By: fqqdk</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-1768</link>
		<dc:creator>fqqdk</dc:creator>
		<pubDate>Sat, 29 Aug 2009 08:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-1768</guid>
		<description>Al: that&#039;s true, so if the little nitpicky details of building a House adds up to grow too complex, the creation logic (logic of the HouseBuilder, which is separated from the logic of the House) can also be refactored into multiple objects, so you can have a GeneralHouseBuilder who delegates to a Plumber, so I see no real problems here. :) And then GeneralHouseBuilder will have a dependency, but we can apply DI to the GeneralHouseBuilder. By the time we get there, we can happily rename it to HouseConstructionShop. It can have a Plumber, an Electrician, and all the other subcontructors injected. :D But at this level the metaphor is starting to get out of touch, so we should just leave it alone now. :)</description>
		<content:encoded><![CDATA[<p>Al: that&#8217;s true, so if the little nitpicky details of building a House adds up to grow too complex, the creation logic (logic of the HouseBuilder, which is separated from the logic of the House) can also be refactored into multiple objects, so you can have a GeneralHouseBuilder who delegates to a Plumber, so I see no real problems here. <img src='http://misko.hevery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  And then GeneralHouseBuilder will have a dependency, but we can apply DI to the GeneralHouseBuilder. By the time we get there, we can happily rename it to HouseConstructionShop. It can have a Plumber, an Electrician, and all the other subcontructors injected. <img src='http://misko.hevery.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  But at this level the metaphor is starting to get out of touch, so we should just leave it alone now. <img src='http://misko.hevery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Al</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-1766</link>
		<dc:creator>Al</dc:creator>
		<pubDate>Sat, 29 Aug 2009 01:43:37 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-1766</guid>
		<description>True, but it would be inefficient and risky for the general contractor to buy all the construction materials he deems necessary and then inject them into the sub contractor&#039;s shop.

As a practical matter, the sub contractor knows exactly what components are needed, and has much more knowledge of how they fit together.  The general contractor has enough to worry about without delving into the implementation details of how the sink and faucet fit together.

If the plumbing regulations change and a different type of pipe is required, only the plumber has to modify his methods.  The general contractor does not experience a disruption, does not have to learn new methods, and does not have to change the way he works.</description>
		<content:encoded><![CDATA[<p>True, but it would be inefficient and risky for the general contractor to buy all the construction materials he deems necessary and then inject them into the sub contractor&#8217;s shop.</p>
<p>As a practical matter, the sub contractor knows exactly what components are needed, and has much more knowledge of how they fit together.  The general contractor has enough to worry about without delving into the implementation details of how the sink and faucet fit together.</p>
<p>If the plumbing regulations change and a different type of pipe is required, only the plumber has to modify his methods.  The general contractor does not experience a disruption, does not have to learn new methods, and does not have to change the way he works.</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-1750</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Wed, 26 Aug 2009 07:54:56 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-1750</guid>
		<description>@Al,

Unit testing and good OO go hand in hand, not against each other. My code has greatly improved once I have started test first development. Dependency injection helps even more with that. So in your case of wanting different kinds of kitchens you would have a house builder which would be responsible for creating the right kitchen and than injecting it into the house. A lot of people put the responsibility of making a kitchen into the house, but have you ever seen a house which con build a kitchen, but I have seen a lot of house builders (aka sub-contractors) which know how to come in and build me one.</description>
		<content:encoded><![CDATA[<p>@Al,</p>
<p>Unit testing and good OO go hand in hand, not against each other. My code has greatly improved once I have started test first development. Dependency injection helps even more with that. So in your case of wanting different kinds of kitchens you would have a house builder which would be responsible for creating the right kitchen and than injecting it into the house. A lot of people put the responsibility of making a kitchen into the house, but have you ever seen a house which con build a kitchen, but I have seen a lot of house builders (aka sub-contractors) which know how to come in and build me one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Al</title>
		<link>http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/comment-page-1/#comment-1746</link>
		<dc:creator>Al</dc:creator>
		<pubDate>Wed, 26 Aug 2009 01:08:30 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-1746</guid>
		<description>This is really based on experience, particularly with code that lasts several years (and therefore becomes a cash cow).  It&#039;s not just a matter of typing; it&#039;s a question of encapsulation.  And I see it as a conflict between a view unit testing and good object-oriented design.

For example, I may want to come out with a new, low-cost kind of house without a kitchen.  I may want a new version of my app where the kitchen is optional, and is not created until the use clicks the &quot;add kitchen&quot; button and chooses the color.  Or I may want to implement a new kind of kitchen and allow application logic to choose which one.  These cases are examples of business rules, and really belong in the House class.</description>
		<content:encoded><![CDATA[<p>This is really based on experience, particularly with code that lasts several years (and therefore becomes a cash cow).  It&#8217;s not just a matter of typing; it&#8217;s a question of encapsulation.  And I see it as a conflict between a view unit testing and good object-oriented design.</p>
<p>For example, I may want to come out with a new, low-cost kind of house without a kitchen.  I may want a new version of my app where the kitchen is optional, and is not created until the use clicks the &#8220;add kitchen&#8221; button and chooses the color.  Or I may want to implement a new kind of kitchen and allow application logic to choose which one.  These cases are examples of business rules, and really belong in the House class.</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-1341</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Fri, 10 Jul 2009 13:53:32 +0000</pubDate>
		<guid isPermaLink="false">http://s90424825.onlinehome.us/blog/?p=41#comment-1341</guid>
		<description>@al
is this your theory or actual experience?  My expereince, especialy when using DI frameworks is that the code becomes much cleaner. Yes it is slightly more typing but the result is well worth it. Especialy from the maintainabilitypoint of view.</description>
		<content:encoded><![CDATA[<p>@al<br />
is this your theory or actual experience?  My expereince, especialy when using DI frameworks is that the code becomes much cleaner. Yes it is slightly more typing but the result is well worth it. Especialy from the maintainabilitypoint of view.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
