<?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: Managing Object Lifetimes</title>
	<atom:link href="http://misko.hevery.com/2009/04/15/managing-object-lifetimes/feed/" rel="self" type="application/rss+xml" />
	<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/</link>
	<description>Testability Explorer</description>
	<lastBuildDate>Fri, 30 Jul 2010 03:59:03 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: mciasco</title>
		<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/comment-page-1/#comment-1915</link>
		<dc:creator>mciasco</dc:creator>
		<pubDate>Mon, 21 Sep 2009 13:22:08 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=456#comment-1915</guid>
		<description>@David
This is not a good example, cause L&#039;s constructor needs a parameter &quot;key&quot; of string type. Parameters such like that are not injectable cause a factory for L does not know which string have to be passed to the constructor during the real build process of L.

However, the question is: why should I pass a parameter in a constructor if it is used as a temporary object inside of it, probably just to get some other object from that parameter? This is a clear violation of the Law of the Demeter. If L needs a string-key to be able to be bound to a particular instance of S, why don&#039;t ask for S directly in its constructor?</description>
		<content:encoded><![CDATA[<p>@David<br />
This is not a good example, cause L&#8217;s constructor needs a parameter &#8220;key&#8221; of string type. Parameters such like that are not injectable cause a factory for L does not know which string have to be passed to the constructor during the real build process of L.</p>
<p>However, the question is: why should I pass a parameter in a constructor if it is used as a temporary object inside of it, probably just to get some other object from that parameter? This is a clear violation of the Law of the Demeter. If L needs a string-key to be able to be bound to a particular instance of S, why don&#8217;t ask for S directly in its constructor?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David V. Corbin</title>
		<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/comment-page-1/#comment-1448</link>
		<dc:creator>David V. Corbin</dc:creator>
		<pubDate>Mon, 27 Jul 2009 19:25:06 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=456#comment-1448</guid>
		<description>Misko.. [Yes I know it has been two months]

Consider a class S which has a string key.

You are designing a class L which requires a valid key to an S object.

You can design L&#039;s constructor to take a string, but then you have the overhead of validating it.

Or, you can have the constructor take an instance of S and simple store (in a readonly field) the Key (which is already valid since it came from an existing S)

How is S is short lived, and L is long lived (funny how that worked out), then you have the exact scenario I was referring to.

When the constructor exits, there are no referneces between the Short Lived and Long Lives objects in either direction. Yes by passing the short to the long as only a stack transaction, the goals are fully achieved with no overhead.</description>
		<content:encoded><![CDATA[<p>Misko.. [Yes I know it has been two months]</p>
<p>Consider a class S which has a string key.</p>
<p>You are designing a class L which requires a valid key to an S object.</p>
<p>You can design L&#8217;s constructor to take a string, but then you have the overhead of validating it.</p>
<p>Or, you can have the constructor take an instance of S and simple store (in a readonly field) the Key (which is already valid since it came from an existing S)</p>
<p>How is S is short lived, and L is long lived (funny how that worked out), then you have the exact scenario I was referring to.</p>
<p>When the constructor exits, there are no referneces between the Short Lived and Long Lives objects in either direction. Yes by passing the short to the long as only a stack transaction, the goals are fully achieved with no overhead.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/comment-page-1/#comment-1142</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Sat, 30 May 2009 02:02:01 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=456#comment-1142</guid>
		<description>@David,

passing a short lived object through a constructor is really confusing. Since you either have a bug because you are not clearing it or you will clear the reference later which implies that you only need the object temporarily. If you need something temporarily than that suggest that your lifetime is longer than it should be or you only need it in constructor which implies that you are doing work in constructor. I like to declare all of the fields which I get through constructor as final. Which is a hint to the reader that they are not changing and are needed for the duration of the object lifetime. On the other hand passing it in through stack implies that you will probably not keep a reference as it is a temporary thing you need to get the work done.</description>
		<content:encoded><![CDATA[<p>@David,</p>
<p>passing a short lived object through a constructor is really confusing. Since you either have a bug because you are not clearing it or you will clear the reference later which implies that you only need the object temporarily. If you need something temporarily than that suggest that your lifetime is longer than it should be or you only need it in constructor which implies that you are doing work in constructor. I like to declare all of the fields which I get through constructor as final. Which is a hint to the reader that they are not changing and are needed for the duration of the object lifetime. On the other hand passing it in through stack implies that you will probably not keep a reference as it is a temporary thing you need to get the work done.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David V. Corbin</title>
		<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/comment-page-1/#comment-1140</link>
		<dc:creator>David V. Corbin</dc:creator>
		<pubDate>Fri, 29 May 2009 15:04:17 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=456#comment-1140</guid>
		<description>An excellent article...

One &quot;Quibble&quot;..There is no problem per se with passing a short lived to a long lived constructor parameter. It is NO different than passing it as a parameter to ANY method.

The problem (which I believe was your intent) was keeping a reference to a shorter lived that exceeds the scope of a single call from the short lived into the long lived.</description>
		<content:encoded><![CDATA[<p>An excellent article&#8230;</p>
<p>One &#8220;Quibble&#8221;..There is no problem per se with passing a short lived to a long lived constructor parameter. It is NO different than passing it as a parameter to ANY method.</p>
<p>The problem (which I believe was your intent) was keeping a reference to a shorter lived that exceeds the scope of a single call from the short lived into the long lived.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: igorbrejc.net &#187; Fresh Catch For May 5th</title>
		<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/comment-page-1/#comment-950</link>
		<dc:creator>igorbrejc.net &#187; Fresh Catch For May 5th</dc:creator>
		<pubDate>Tue, 05 May 2009 07:03:43 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=456#comment-950</guid>
		<description>[...] Managing Object Lifetimes [...]</description>
		<content:encoded><![CDATA[<p>[...] Managing Object Lifetimes [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Przemek</title>
		<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/comment-page-1/#comment-905</link>
		<dc:creator>Przemek</dc:creator>
		<pubDate>Thu, 23 Apr 2009 12:29:19 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=456#comment-905</guid>
		<description>@MatI don&#039;t know what rule says about it, but I learned one thing: you&#039;d better be careful with publishing events to shorter-lived objects or their lifetime will exceed your expectations ;)In practice I&#039;ve used two techniques: one was to carefully unregister my short-lived listeners at the end of their life. Second was to use weak references to the listeners from the event publisher.</description>
		<content:encoded><![CDATA[<p>@MatI don&#8217;t know what rule says about it, but I learned one thing: you&#8217;d better be careful with publishing events to shorter-lived objects or their lifetime will exceed your expectations <img src='http://misko.hevery.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> In practice I&#8217;ve used two techniques: one was to carefully unregister my short-lived listeners at the end of their life. Second was to use weak references to the listeners from the event publisher.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mat Noguchi</title>
		<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/comment-page-1/#comment-891</link>
		<dc:creator>Mat Noguchi</dc:creator>
		<pubDate>Fri, 17 Apr 2009 16:45:17 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=456#comment-891</guid>
		<description>Do event handlers fall outside this rule? I&#039;m trying to think of how to have a long lived object publish events without having a reference to shorter lived objects...

MSN</description>
		<content:encoded><![CDATA[<p>Do event handlers fall outside this rule? I&#8217;m trying to think of how to have a long lived object publish events without having a reference to shorter lived objects&#8230;</p>
<p>MSN</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/comment-page-1/#comment-884</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Thu, 16 Apr 2009 13:15:41 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=456#comment-884</guid>
		<description>@Jonathan, 

Thanks, I updated the text...</description>
		<content:encoded><![CDATA[<p>@Jonathan, </p>
<p>Thanks, I updated the text&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Hartley</title>
		<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/comment-page-1/#comment-883</link>
		<dc:creator>Jonathan Hartley</dc:creator>
		<pubDate>Thu, 16 Apr 2009 12:46:11 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=456#comment-883</guid>
		<description>&#039;something thanks&#039; == &#039;This is something I haven&#039;t thought about at all before, but makes brilliant sense - Thanks!&#039;</description>
		<content:encoded><![CDATA[<p>&#8217;something thanks&#8217; == &#8216;This is something I haven&#8217;t thought about at all before, but makes brilliant sense &#8211; Thanks!&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Hartley</title>
		<link>http://misko.hevery.com/2009/04/15/managing-object-lifetimes/comment-page-1/#comment-882</link>
		<dc:creator>Jonathan Hartley</dc:creator>
		<pubDate>Thu, 16 Apr 2009 12:45:06 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=456#comment-882</guid>
		<description>Brilliant article, something thanks!

The sentence beginning para 2 is ambiguous:

&gt;&gt; Now I believe that each object should have
&gt;&gt; reference to other objects whose lifetime is
&gt;&gt; equal or shorter to the object. 

This says to me the opposite of what I think you intend. How about replacing it with something like:

&gt;&gt; I believe objects should only maintain references to other objects that are longer-lived.

Or have I misunderstood again? :-)</description>
		<content:encoded><![CDATA[<p>Brilliant article, something thanks!</p>
<p>The sentence beginning para 2 is ambiguous:</p>
<p>&gt;&gt; Now I believe that each object should have<br />
&gt;&gt; reference to other objects whose lifetime is<br />
&gt;&gt; equal or shorter to the object. </p>
<p>This says to me the opposite of what I think you intend. How about replacing it with something like:</p>
<p>&gt;&gt; I believe objects should only maintain references to other objects that are longer-lived.</p>
<p>Or have I misunderstood again? <img src='http://misko.hevery.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
