<?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: Flaw: Constructor does Real Work</title>
	<atom:link href="http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/feed/" rel="self" type="application/rss+xml" />
	<link>http://misko.hevery.com</link>
	<description>Testability Explorer</description>
	<lastBuildDate>Tue, 09 Mar 2010 04:29:26 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: miluch</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/comment-page-1/#comment-2761</link>
		<dc:creator>miluch</dc:creator>
		<pubDate>Wed, 06 Jan 2010 08:50:29 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=321#comment-2761</guid>
		<description>Hi 
Thanks for a link to your post. I have read it 3 times and I am still not convinced.
Hopefully, after reading comments of this post i can see that I am not the only one who disagrees with you.
The thing i do not understand the most is
&quot;Now there is a difference if the API is meant for my internal consumption or is part of an external API&quot;
How can you guarantee that none of your colleagues will call your &quot;internal consumption API&quot;  ? Use access level modifiers ?


I can agree with guys who proposed using some stubs/mocks  to pass to House constructor.
I would do the same in this case ( using  DI would be even better) but in my triangle scenario it is not about collaborators validation 
but validating internal consistency of object.</description>
		<content:encoded><![CDATA[<p>Hi<br />
Thanks for a link to your post. I have read it 3 times and I am still not convinced.<br />
Hopefully, after reading comments of this post i can see that I am not the only one who disagrees with you.<br />
The thing i do not understand the most is<br />
&#8220;Now there is a difference if the API is meant for my internal consumption or is part of an external API&#8221;<br />
How can you guarantee that none of your colleagues will call your &#8220;internal consumption API&#8221;  ? Use access level modifiers ?</p>
<p>I can agree with guys who proposed using some stubs/mocks  to pass to House constructor.<br />
I would do the same in this case ( using  DI would be even better) but in my triangle scenario it is not about collaborators validation<br />
but validating internal consistency of object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/comment-page-1/#comment-2756</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Wed, 06 Jan 2010 00:32:09 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=321#comment-2756</guid>
		<description>see: http://misko.hevery.com/2009/02/09/to-assert-or-not-to-assert/</description>
		<content:encoded><![CDATA[<p>see: <a href="http://misko.hevery.com/2009/02/09/to-assert-or-not-to-assert/" rel="nofollow">http://misko.hevery.com/2009/02/09/to-assert-or-not-to-assert/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: miluch</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/comment-page-1/#comment-2754</link>
		<dc:creator>miluch</dc:creator>
		<pubDate>Tue, 05 Jan 2010 19:48:20 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=321#comment-2754</guid>
		<description>Hi

I am wondering what&#039;s your opinion about checking invariants in constructor.
Let&#039;s say you want to create triangle object, feeding it&#039;s constructor with degrees of 3 angles.

Triangle(int angle1, int angle2, int angle3)

For triangle all interior angles total to 180 degrees. 
Since I truly believe that objects should be responsible for ensuring validity of its state, checking  if sum of user provided angles equals to 180 should be done in constructor - you would end up having some conditional logic in your constructor...

If invariant is violated i would throw IllegalArgumentException...

This approach seems to be very attractive  - you will always work with valid triangles, but it kills testability:
To test any of triangle behavior (for example checking if triangle is right-angled) you first need to instantiate it feeding it with correct angle values.
For triangle example it does not seem to be the case, but in more complex scenarios instantiating object to be tested can be quite hard - not because of its hard coded collaborators but because of its invariants.</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>I am wondering what&#8217;s your opinion about checking invariants in constructor.<br />
Let&#8217;s say you want to create triangle object, feeding it&#8217;s constructor with degrees of 3 angles.</p>
<p>Triangle(int angle1, int angle2, int angle3)</p>
<p>For triangle all interior angles total to 180 degrees.<br />
Since I truly believe that objects should be responsible for ensuring validity of its state, checking  if sum of user provided angles equals to 180 should be done in constructor &#8211; you would end up having some conditional logic in your constructor&#8230;</p>
<p>If invariant is violated i would throw IllegalArgumentException&#8230;</p>
<p>This approach seems to be very attractive  &#8211; you will always work with valid triangles, but it kills testability:<br />
To test any of triangle behavior (for example checking if triangle is right-angled) you first need to instantiate it feeding it with correct angle values.<br />
For triangle example it does not seem to be the case, but in more complex scenarios instantiating object to be tested can be quite hard &#8211; not because of its hard coded collaborators but because of its invariants.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Einführung in TDD &#38; Clean Code Talks &#124; geekcloud.org</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/comment-page-1/#comment-2430</link>
		<dc:creator>Einführung in TDD &#38; Clean Code Talks &#124; geekcloud.org</dc:creator>
		<pubDate>Sun, 22 Nov 2009 15:07:57 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=321#comment-2430</guid>
		<description>[...] Flaw #1: Constructor does Real Work [...]</description>
		<content:encoded><![CDATA[<p>[...] Flaw #1: Constructor does Real Work [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trimming the fat around constructors &#171; Curly Braces</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/comment-page-1/#comment-2347</link>
		<dc:creator>Trimming the fat around constructors &#171; Curly Braces</dc:creator>
		<pubDate>Mon, 16 Nov 2009 09:44:24 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=321#comment-2347</guid>
		<description>[...] 1. Misko Hevery &#8211; The Testability Explorer Blog [...]</description>
		<content:encoded><![CDATA[<p>[...] 1. Misko Hevery &#8211; The Testability Explorer Blog [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giorgio Sironi</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/comment-page-1/#comment-2036</link>
		<dc:creator>Giorgio Sironi</dc:creator>
		<pubDate>Wed, 07 Oct 2009 18:56:20 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=321#comment-2036</guid>
		<description>Bill,
in my opinion you should not do work in the constructor of a client, and the possible cases are two:
- the Client needs a collaborator with the same lifecycle. So pass it as an argument of the constructor of the Client.
- the Clicnt needs to create an object at a certain point of execution, in a method. So pass in a Factory in the Client&#039;s constructor.</description>
		<content:encoded><![CDATA[<p>Bill,<br />
in my opinion you should not do work in the constructor of a client, and the possible cases are two:<br />
- the Client needs a collaborator with the same lifecycle. So pass it as an argument of the constructor of the Client.<br />
- the Clicnt needs to create an object at a certain point of execution, in a method. So pass in a Factory in the Client&#8217;s constructor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Sanders</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/comment-page-1/#comment-2002</link>
		<dc:creator>Bill Sanders</dc:creator>
		<pubDate>Sun, 04 Oct 2009 09:24:05 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=321#comment-2002</guid>
		<description>Does any of this apply to a Client class? (I use the term &#039;Client&#039; in the way GoF does.) Following the principle of having the constructor do no real work has solved all kinds of problems in my patterns, but when I go to call the design, I have to use the constructor method in the Client to instantiate objects. In other words, the constructor in the Client does real work.

Thanks,
Bill</description>
		<content:encoded><![CDATA[<p>Does any of this apply to a Client class? (I use the term &#8216;Client&#8217; in the way GoF does.) Following the principle of having the constructor do no real work has solved all kinds of problems in my patterns, but when I go to call the design, I have to use the constructor method in the Client to instantiate objects. In other words, the constructor in the Client does real work.</p>
<p>Thanks,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wicket is complicated &#171; Lumpynose&#8217;s Weblog</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/comment-page-1/#comment-1918</link>
		<dc:creator>Wicket is complicated &#171; Lumpynose&#8217;s Weblog</dc:creator>
		<pubDate>Tue, 22 Sep 2009 06:35:30 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=321#comment-1918</guid>
		<description>[...] Sometimes in the constructor they call methods on the dao.  That just seems wrong. For why, see this article by Miško Hevery. [...]</description>
		<content:encoded><![CDATA[<p>[...] Sometimes in the constructor they call methods on the dao.  That just seems wrong. For why, see this article by Miško Hevery. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MeBigFatGuy</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/comment-page-1/#comment-1867</link>
		<dc:creator>MeBigFatGuy</dc:creator>
		<pubDate>Fri, 11 Sep 2009 21:15:29 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=321#comment-1867</guid>
		<description>Kicking off a thread in a ctor is no good either.</description>
		<content:encoded><![CDATA[<p>Kicking off a thread in a ctor is no good either.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicolas</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/comment-page-1/#comment-1303</link>
		<dc:creator>Nicolas</dc:creator>
		<pubDate>Mon, 06 Jul 2009 20:00:27 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=321#comment-1303</guid>
		<description>All this stuff seems biased to Java, not general guidelines.

Nothing is &quot;injectable&quot; in C++, and you can&#039;t always subclass to make a mock (classes don&#039;t use virtual methods unless really needed).</description>
		<content:encoded><![CDATA[<p>All this stuff seems biased to Java, not general guidelines.</p>
<p>Nothing is &#8220;injectable&#8221; in C++, and you can&#8217;t always subclass to make a mock (classes don&#8217;t use virtual methods unless really needed).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
