<?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: IDisposable Part 2 &#8211; Subclass from an IDisposable class</title>
	<atom:link href="http://reedcopsey.com/2009/03/30/idisposable-part-2-subclass-from-an-idisposable-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://reedcopsey.com/2009/03/30/idisposable-part-2-subclass-from-an-idisposable-class/</link>
	<description>Thoughts on C#, WPF, .NET, and programming for Scientific Visualization</description>
	<lastBuildDate>Fri, 11 May 2012 16:07:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Reed</title>
		<link>http://reedcopsey.com/2009/03/30/idisposable-part-2-subclass-from-an-idisposable-class/#comment-1225</link>
		<dc:creator>Reed</dc:creator>
		<pubDate>Tue, 07 Dec 2010 04:42:00 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=14#comment-1225</guid>
		<description>supercat:  

While I see your position on using an integer, I, personally, disagree with this idea.  By exposing &quot;Disposed&quot; to any other classes, including subclasses, you open up the possibility of your code behaving inappropriately.

Each class/subclass needs its own private tracking for safety purposes.  This is the only way to guarantee proper tracking of disposal.  I agree with this statement of yours: &quot;would cause problems if the flag were exposed&quot;.  That is why I advocate that the disposed boolean should be private, not protected or public.</description>
		<content:encoded><![CDATA[<p>supercat:  </p>
<p>While I see your position on using an integer, I, personally, disagree with this idea.  By exposing &#8220;Disposed&#8221; to any other classes, including subclasses, you open up the possibility of your code behaving inappropriately.</p>
<p>Each class/subclass needs its own private tracking for safety purposes.  This is the only way to guarantee proper tracking of disposal.  I agree with this statement of yours: &#8220;would cause problems if the flag were exposed&#8221;.  That is why I advocate that the disposed boolean should be private, not protected or public.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: supercat</title>
		<link>http://reedcopsey.com/2009/03/30/idisposable-part-2-subclass-from-an-idisposable-class/#comment-1221</link>
		<dc:creator>supercat</dc:creator>
		<pubDate>Wed, 01 Dec 2010 22:46:42 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=14#comment-1221</guid>
		<description>The normal dispose pattern&#039;s handling of the Disposed flag is a bit sloppy.  It&#039;s serviceable if the Disposed flag isn&#039;t shared between derived classes, but would cause problems if the flag were exposed.

The disposed flag would be better as an integer, which could then be updated and tested via Interlocked.Exchange in the public Dispose method; a Disposed property could be exposed publicly which would indicate whether the flag was set.

One shouldn&#039;t worry that a disposer which set the Disposed flag and threw an exception might prevent a finalizer from running, since classes which hold managed resources shouldn&#039;t have finalizers in the first place.</description>
		<content:encoded><![CDATA[<p>The normal dispose pattern&#8217;s handling of the Disposed flag is a bit sloppy.  It&#8217;s serviceable if the Disposed flag isn&#8217;t shared between derived classes, but would cause problems if the flag were exposed.</p>
<p>The disposed flag would be better as an integer, which could then be updated and tested via Interlocked.Exchange in the public Dispose method; a Disposed property could be exposed publicly which would indicate whether the flag was set.</p>
<p>One shouldn&#8217;t worry that a disposer which set the Disposed flag and threw an exception might prevent a finalizer from running, since classes which hold managed resources shouldn&#8217;t have finalizers in the first place.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reed</title>
		<link>http://reedcopsey.com/2009/03/30/idisposable-part-2-subclass-from-an-idisposable-class/#comment-1195</link>
		<dc:creator>Reed</dc:creator>
		<pubDate>Wed, 10 Nov 2010 16:35:08 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=14#comment-1195</guid>
		<description>Peter:

It&#039;s a matter of protection.  The bool is a private implementation detail - technically, it&#039;s only required if you have no way to tell via state that you&#039;ve been disposed.  That being said, by making it protected, a subclass could &quot;undispose&quot; you if it did something incorrectly.  A protected property get method could be appropriate, as it prevents that case.

However, adding a protected property getter is not part of the &quot;official&quot; pattern.  I was trying to stick to the official pattern here, which doesn&#039;t include that.  In that case, using your own disposed is required.  For example, the above pattern works if subclassing a framework IDisposable - in which case you can&#039;t change the base class.

-Reed</description>
		<content:encoded><![CDATA[<p>Peter:</p>
<p>It&#8217;s a matter of protection.  The bool is a private implementation detail &#8211; technically, it&#8217;s only required if you have no way to tell via state that you&#8217;ve been disposed.  That being said, by making it protected, a subclass could &#8220;undispose&#8221; you if it did something incorrectly.  A protected property get method could be appropriate, as it prevents that case.</p>
<p>However, adding a protected property getter is not part of the &#8220;official&#8221; pattern.  I was trying to stick to the official pattern here, which doesn&#8217;t include that.  In that case, using your own disposed is required.  For example, the above pattern works if subclassing a framework IDisposable &#8211; in which case you can&#8217;t change the base class.</p>
<p>-Reed</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter M.</title>
		<link>http://reedcopsey.com/2009/03/30/idisposable-part-2-subclass-from-an-idisposable-class/#comment-1194</link>
		<dc:creator>Peter M.</dc:creator>
		<pubDate>Wed, 10 Nov 2010 12:12:55 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=14#comment-1194</guid>
		<description>Interesting posts about IDisposable.
I was wondering why you would create a new private bool disposed in your subclass. Why not make the member in the superclass protected? It would make your code a little smaller (which usually makes it more readable). Or are protected members considered a bad practice?</description>
		<content:encoded><![CDATA[<p>Interesting posts about IDisposable.<br />
I was wondering why you would create a new private bool disposed in your subclass. Why not make the member in the superclass protected? It would make your code a little smaller (which usually makes it more readable). Or are protected members considered a bad practice?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reed Copsey, Jr. : IDisposable Part 3 &#8211; Encapsulating an IDisposable class</title>
		<link>http://reedcopsey.com/2009/03/30/idisposable-part-2-subclass-from-an-idisposable-class/#comment-12</link>
		<dc:creator>Reed Copsey, Jr. : IDisposable Part 3 &#8211; Encapsulating an IDisposable class</dc:creator>
		<pubDate>Fri, 01 May 2009 00:18:09 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=14#comment-12</guid>
		<description>[...] resources.&#160; In this series, we’re going to build on our LicenseAGenerator class from Part 2, encapsulating inside of a class which will use it [...]</description>
		<content:encoded><![CDATA[<p>[...] resources.&#160; In this series, we’re going to build on our LicenseAGenerator class from Part 2, encapsulating inside of a class which will use it [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
 
