<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Should Interfaces Derive from IDisposable?</title><link>http://blogs.msdn.com/mthalman/archive/2009/03/13/should-interfaces-derive-from-idisposable.aspx</link><description>I've been defining some interfaces for some classes in our code. The classes implement IDisposable and I was wondering whether the class' corresponding interface should also derive from IDisposable. For example: class Foo : IFoo, IDisposable { public</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Should Interfaces Derive from IDisposable?</title><link>http://blogs.msdn.com/mthalman/archive/2009/03/13/should-interfaces-derive-from-idisposable.aspx#9473495</link><pubDate>Fri, 13 Mar 2009 21:28:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9473495</guid><dc:creator>Rory Primrose</dc:creator><description>&lt;P&gt;I agree. IDisposable is only relevant to an instance of a class and doesn't mean anything for an interface. To place it on an interface would be an unnecessary constraint.&lt;/P&gt;
&lt;P&gt;As a side note, you may be interested in this:&lt;/P&gt;
&lt;P&gt;&amp;lt;a href="&lt;A href="http://www.neovolve.com/post/2008/07/03/reflection-pop-quiz-does-interface-inheritance-exist.aspx%22%3Ehttp://www.neovolve.com/post/2008/07/03/reflection-pop-quiz-does-interface-inheritance-exist.aspx%3C/a%3E" rel=nofollow target=_new&gt;http://www.neovolve.com/post/2008/07/03/reflection-pop-quiz-does-interface-inheritance-exist.aspx&lt;/a&gt;'&gt;http://www.neovolve.com/post/2008/07/03/reflection-pop-quiz-does-interface-inheritance-exist.aspx"&amp;gt;http://www.neovolve.com/post/2008/07/03/reflection-pop-quiz-does-interface-inheritance-exist.aspx&amp;lt;/a&amp;gt;&lt;/A&gt;&lt;/P&gt;</description></item><item><title>re: Should Interfaces Derive from IDisposable?</title><link>http://blogs.msdn.com/mthalman/archive/2009/03/13/should-interfaces-derive-from-idisposable.aspx#9473950</link><pubDate>Sat, 14 Mar 2009 03:19:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9473950</guid><dc:creator>Joe Albahari</dc:creator><description>&lt;P&gt;This reasoning might also apply to abstract classes such as Stream - a MemoryStream, for example, doesn't need disposing.&lt;/P&gt;
&lt;P&gt;The counterargument is that manual disposal is clumsy - and in most cases requires a try/finally block. It's also less discoverable - consumers might not realize that they have to dispose an object if working via interfaces.&lt;/P&gt;
&lt;P&gt;For interfaces such as IDbConnection and IDataReader - whose implementations always need IDisposable, it would be awkward having to deal with a cast and try/finally block whenever it was used. The following code is the simplest and most natural:&lt;/P&gt;
&lt;P&gt;using (IDataReader reader = myIDbCommand.ExecuteReader())&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;Same deal with streams.&lt;/P&gt;
&lt;P&gt;So maybe it depends on the particular situation.&lt;/P&gt;</description></item></channel></rss>