<?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: Is There A Good Reason To Hide Inherited Members?</title>
	<atom:link href="http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/feed/" rel="self" type="application/rss+xml" />
	<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/</link>
	<description>Trying to walk that thin line between intelligence and ignorance</description>
	<lastBuildDate>Thu, 29 Jul 2010 21:01:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Dathan Bennett</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-27193</link>
		<dc:creator>Dathan Bennett</dc:creator>
		<pubDate>Wed, 03 Feb 2010 19:48:56 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-27193</guid>
		<description>As with Richard and Maarten, I use &lt;i&gt;new&lt;/i&gt; to retype base class properties and methods to a type that&#039;s appropriate to the derived class, but I always to do in a way that plays nice.  The only potential concern would be the following:

&lt;code&gt;
class BaseClass
{
    public Model TheModel { get; set; }
}

class DerivedClass
{
    public new DerivedModel TheModel 
    { 
        get { return (DerivedModel)base.Model; } 
        set { base.Model = value; } 
    }
}

DerivedClass instance = new DerivedClass() { TheModel = new DerivedModel }; // fine
((BaseClass)instance).TheModel = new IncompatibleModel(); // will pass because IncompatibleModel inherits from Model, but trouble is brewing
Console.WriteLine(instance.TheModel); // typecast failure in the getter
&lt;/code&gt;

But I control for that in code, so I feel safe using it.

I&#039;ve also used it in slightly less safe context to convert the value of CheckBox.Checked to Nullable.  (If Checked = null is set, we set the display to render the indeterminate checked state, and set &quot;false&quot; to the underlying Checked property).  So long as I always reference Checked by a derived class reference or through reflection (e.g., data binding), everything&#039;s fine, but I feel less sanguine about this solution.</description>
		<content:encoded><![CDATA[<p>As with Richard and Maarten, I use <i>new</i> to retype base class properties and methods to a type that&#8217;s appropriate to the derived class, but I always to do in a way that plays nice.  The only potential concern would be the following:</p>
<p><code><br />
class BaseClass<br />
{<br />
    public Model TheModel { get; set; }<br />
}</p>
<p>class DerivedClass<br />
{<br />
    public new DerivedModel TheModel<br />
    {<br />
        get { return (DerivedModel)base.Model; }<br />
        set { base.Model = value; }<br />
    }<br />
}</p>
<p>DerivedClass instance = new DerivedClass() { TheModel = new DerivedModel }; // fine<br />
((BaseClass)instance).TheModel = new IncompatibleModel(); // will pass because IncompatibleModel inherits from Model, but trouble is brewing<br />
Console.WriteLine(instance.TheModel); // typecast failure in the getter<br />
</code></p>
<p>But I control for that in code, so I feel safe using it.</p>
<p>I&#8217;ve also used it in slightly less safe context to convert the value of CheckBox.Checked to Nullable.  (If Checked = null is set, we set the display to render the indeterminate checked state, and set &#8220;false&#8221; to the underlying Checked property).  So long as I always reference Checked by a derived class reference or through reflection (e.g., data binding), everything&#8217;s fine, but I feel less sanguine about this solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard J Foster</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25654</link>
		<dc:creator>Richard J Foster</dc:creator>
		<pubDate>Thu, 21 Jan 2010 16:00:16 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25654</guid>
		<description>The place I&#039;ve used it is very similar to Maarten Balliauw&#039;s.

Specifically, a base class provided a method returning ISomeType. An inheriting class always provided an ISomeOtherType (where ISomeOtherType inherits from ISomeType). If a reference to the inheriting class was used, I used the new keyword to ensure that when the method was called a reference to an ISomeOtherType was used. This meant it was not necessary for any caller to know that the value returned could be cast to ISomeOtherType.</description>
		<content:encoded><![CDATA[<p>The place I&#8217;ve used it is very similar to Maarten Balliauw&#8217;s.</p>
<p>Specifically, a base class provided a method returning ISomeType. An inheriting class always provided an ISomeOtherType (where ISomeOtherType inherits from ISomeType). If a reference to the inheriting class was used, I used the new keyword to ensure that when the method was called a reference to an ISomeOtherType was used. This meant it was not necessary for any caller to know that the value returned could be cast to ISomeOtherType.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas G. Mayfield</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25536</link>
		<dc:creator>Thomas G. Mayfield</dc:creator>
		<pubDate>Wed, 20 Jan 2010 16:29:50 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25536</guid>
		<description>Side note: I&#039;d forgotten about this, but I actually needed &quot;new&quot; yesterday to work around a problem with the Spark View Engine. It doesn&#039;t create a strongly-typed HtmlHelper in its view classes: http://groups.google.com/group/spark-dev/browse_thread/thread/d59e8675d9a78916/747c170bd7932064#747c170bd7932064  But that&#039;s another case like Maarten&#039;s above, where code that uses a reference to the base class still functions the same.</description>
		<content:encoded><![CDATA[<p>Side note: I&#8217;d forgotten about this, but I actually needed &#8220;new&#8221; yesterday to work around a problem with the Spark View Engine. It doesn&#8217;t create a strongly-typed HtmlHelper in its view classes: <a href="http://groups.google.com/group/spark-dev/browse_thread/thread/d59e8675d9a78916/747c170bd7932064#747c170bd7932064" rel="nofollow">http://groups.google.com/group/spark-dev/browse_thread/thread/d59e8675d9a78916/747c170bd7932064#747c170bd7932064</a>  But that&#8217;s another case like Maarten&#8217;s above, where code that uses a reference to the base class still functions the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas G. Mayfield</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25535</link>
		<dc:creator>Thomas G. Mayfield</dc:creator>
		<pubDate>Wed, 20 Jan 2010 16:26:38 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25535</guid>
		<description>@James I use &quot;new&quot; to change scope with framework (vendor, OSS libraries, whatever) code that&#039;s marked &quot;protected internal&quot; in the base implementation.  When I&#039;m replacing a group of classes that form a single piece of functionality (the same reason the original code vendor marked it internal), I have no qualms about it having the same scope as it originally had (so &quot;new protected internal&quot;), but in my own project that extends it.

@Davy My most common use case for &quot;new&quot; is on interfaces, where I want to have both a generic and non-generic version.  But &quot;new&quot; on interfaces (where an implementing class is required to provide both versions) doesn&#039;t often lead to the kind of bugs you&#039;re describing.</description>
		<content:encoded><![CDATA[<p>@James I use &#8220;new&#8221; to change scope with framework (vendor, OSS libraries, whatever) code that&#8217;s marked &#8220;protected internal&#8221; in the base implementation.  When I&#8217;m replacing a group of classes that form a single piece of functionality (the same reason the original code vendor marked it internal), I have no qualms about it having the same scope as it originally had (so &#8220;new protected internal&#8221;), but in my own project that extends it.</p>
<p>@Davy My most common use case for &#8220;new&#8221; is on interfaces, where I want to have both a generic and non-generic version.  But &#8220;new&#8221; on interfaces (where an implementing class is required to provide both versions) doesn&#8217;t often lead to the kind of bugs you&#8217;re describing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Hare</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25443</link>
		<dc:creator>James Hare</dc:creator>
		<pubDate>Tue, 19 Jan 2010 15:02:05 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25443</guid>
		<description>@Cameron while that may be valid syntactically, it would be a very dire thing to make a protected field public in a derived class.  You&#039;re then very strongly coupling the subclass and in essence violating the original class.</description>
		<content:encoded><![CDATA[<p>@Cameron while that may be valid syntactically, it would be a very dire thing to make a protected field public in a derived class.  You&#8217;re then very strongly coupling the subclass and in essence violating the original class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cameron Fletcher</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25435</link>
		<dc:creator>Cameron Fletcher</dc:creator>
		<pubDate>Tue, 19 Jan 2010 12:17:21 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25435</guid>
		<description>I&#039;ve used it on occasion to change the scope of an inherited member - eg. make a protected member public - whilst not altering the implemetation. I believe this is a valid use of the new keyword.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve used it on occasion to change the scope of an inherited member &#8211; eg. make a protected member public &#8211; whilst not altering the implemetation. I believe this is a valid use of the new keyword.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mynkow</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25306</link>
		<dc:creator>mynkow</dc:creator>
		<pubDate>Mon, 18 Jan 2010 20:18:10 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25306</guid>
		<description>I want to hide the base class methods because they are useless. I do not want to use them ever. And I use the new keyword because the base classes are from .net framework.</description>
		<content:encoded><![CDATA[<p>I want to hide the base class methods because they are useless. I do not want to use them ever. And I use the new keyword because the base classes are from .net framework.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25298</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 18 Jan 2010 18:59:52 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25298</guid>
		<description>@Mynkow

well, once you pass instances of your derived Combobox to code that requires a Combobox reference and accesses one of those methods, you&#039;ll run into the issues i mentioned.</description>
		<content:encoded><![CDATA[<p>@Mynkow</p>
<p>well, once you pass instances of your derived Combobox to code that requires a Combobox reference and accesses one of those methods, you&#8217;ll run into the issues i mentioned.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mynkow</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25297</link>
		<dc:creator>mynkow</dc:creator>
		<pubDate>Mon, 18 Jan 2010 18:58:22 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25297</guid>
		<description>Well there is one good reason to use the new keyword. At the moment I have nested entities which I want to display in a combobox. I inherit from Combobox and then write my own methods for DataSource, ValueMember, DisplayMember, Items etc.</description>
		<content:encoded><![CDATA[<p>Well there is one good reason to use the new keyword. At the moment I have nested entities which I want to display in a combobox. I inherit from Combobox and then write my own methods for DataSource, ValueMember, DisplayMember, Items etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25290</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 18 Jan 2010 17:29:34 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25290</guid>
		<description>Yet another reason why inheritance is evil:
http://simpleprogrammer.com/2010/01/15/inheritance-is-inherently-evil/

Composition solves most of the problems with concrete class inheritance, because it makes everything explicit.  If you implement an interface and provide a base implementation for that interface, all methods in the interface must be explicitly dealt with.</description>
		<content:encoded><![CDATA[<p>Yet another reason why inheritance is evil:<br />
<a href="http://simpleprogrammer.com/2010/01/15/inheritance-is-inherently-evil/" rel="nofollow">http://simpleprogrammer.com/2010/01/15/inheritance-is-inherently-evil/</a></p>
<p>Composition solves most of the problems with concrete class inheritance, because it makes everything explicit.  If you implement an interface and provide a base implementation for that interface, all methods in the interface must be explicitly dealt with.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25268</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 18 Jan 2010 13:56:32 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25268</guid>
		<description>@Dhananjay

i would prefer virtual-by-default but i do understand their decision to make non-virtual the default.</description>
		<content:encoded><![CDATA[<p>@Dhananjay</p>
<p>i would prefer virtual-by-default but i do understand their decision to make non-virtual the default.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhananjay Goyani</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25263</link>
		<dc:creator>Dhananjay Goyani</dc:creator>
		<pubDate>Mon, 18 Jan 2010 12:54:29 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25263</guid>
		<description>So, do you want all methods to be virtual by default in .NET unless specified otherwise?

Just today morning, I discussed virtual vs non-virtual with my team and here I read your entry. Passed this to my team and they have enjoyed it very much.</description>
		<content:encoded><![CDATA[<p>So, do you want all methods to be virtual by default in .NET unless specified otherwise?</p>
<p>Just today morning, I discussed virtual vs non-virtual with my team and here I read your entry. Passed this to my team and they have enjoyed it very much.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25253</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 18 Jan 2010 09:45:10 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25253</guid>
		<description>@Damien

good point :)</description>
		<content:encoded><![CDATA[<p>@Damien</p>
<p>good point <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25251</link>
		<dc:creator>Damien</dc:creator>
		<pubDate>Mon, 18 Jan 2010 09:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25251</guid>
		<description>You say that in the case of a breaking change in a base class out of your control, you&#039;d do a rename on your method and force your consumers to update. But consider - if you&#039;re only becoming aware of the breaking change due to a compiler warning, how do you expect your consumers to discover *your* breaking change? When they recompile, they&#039;ll now get the base class implementation, and no warning.</description>
		<content:encoded><![CDATA[<p>You say that in the case of a breaking change in a base class out of your control, you&#8217;d do a rename on your method and force your consumers to update. But consider &#8211; if you&#8217;re only becoming aware of the breaking change due to a compiler warning, how do you expect your consumers to discover *your* breaking change? When they recompile, they&#8217;ll now get the base class implementation, and no warning.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Morning Brew - Chris Alcock &#187; The Morning Brew #519</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25248</link>
		<dc:creator>The Morning Brew - Chris Alcock &#187; The Morning Brew #519</dc:creator>
		<pubDate>Mon, 18 Jan 2010 08:24:59 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25248</guid>
		<description>[...] Is There A Good Reason To Hide Inherited Members? - Davy Brion looks at the language functionality which allows you to hide inherited members by supplying your own implementation, and highlights some of the pitfalls in doing this. [...]</description>
		<content:encoded><![CDATA[<p>[...] Is There A Good Reason To Hide Inherited Members? &#8211; Davy Brion looks at the language functionality which allows you to hide inherited members by supplying your own implementation, and highlights some of the pitfalls in doing this. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maarten Balliauw</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25246</link>
		<dc:creator>Maarten Balliauw</dc:creator>
		<pubDate>Mon, 18 Jan 2010 08:19:39 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25246</guid>
		<description>Here&#039;s a use case for the new keyword I used in the past few days:

&lt;code&gt;
public class BaseSomething
{
    public object Model { get; set; }
}

public class BaseSomething
{
    public new TModel Model
    {
        get { return (TModel)base.Model; }
        set { base.Model = value; }
    }
}
&lt;/code&gt;

It should not break anyting, but it provides an extra useful generic layer.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a use case for the new keyword I used in the past few days:</p>
<p><code><br />
public class BaseSomething<br />
{<br />
    public object Model { get; set; }<br />
}</p>
<p>public class BaseSomething<br />
{<br />
    public new TModel Model<br />
    {<br />
        get { return (TModel)base.Model; }<br />
        set { base.Model = value; }<br />
    }<br />
}<br />
</code></p>
<p>It should not break anyting, but it provides an extra useful generic layer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dalibor Carapic</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25211</link>
		<dc:creator>Dalibor Carapic</dc:creator>
		<pubDate>Sun, 17 Jan 2010 19:06:27 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25211</guid>
		<description>I&#039;ve used it in derived Windows Forms Controls in order to override the standard control property but provide different DefaultValue and DesignerSerializationVisibility attributes. The new property just calls the old property so it can not break the code.
Other then that I have not seen it.
While we are on the subject of weird possibilities that C# gives you, why is it not possible to declare virtual interface members which are explicitly implemented?
(explitit implementation of interface member: 
void IInterface.DoSomething(string bla) { })
This one is really anoying to me.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve used it in derived Windows Forms Controls in order to override the standard control property but provide different DefaultValue and DesignerSerializationVisibility attributes. The new property just calls the old property so it can not break the code.<br />
Other then that I have not seen it.<br />
While we are on the subject of weird possibilities that C# gives you, why is it not possible to declare virtual interface members which are explicitly implemented?<br />
(explitit implementation of interface member:<br />
void IInterface.DoSomething(string bla) { })<br />
This one is really anoying to me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michel Grootjans</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25210</link>
		<dc:creator>Michel Grootjans</dc:creator>
		<pubDate>Sun, 17 Jan 2010 18:51:07 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25210</guid>
		<description>Funny, I never really looked at it this way. Although I&#039;m well aware of the &#039;new&#039; keyword and its effects, I never used this feature. I never even considered why you&#039;d want to use this feature, and I have absolutely no idea what the original intent was.</description>
		<content:encoded><![CDATA[<p>Funny, I never really looked at it this way. Although I&#8217;m well aware of the &#8216;new&#8217; keyword and its effects, I never used this feature. I never even considered why you&#8217;d want to use this feature, and I have absolutely no idea what the original intent was.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JeroenH</title>
		<link>http://davybrion.com/blog/2010/01/is-there-a-good-reason-to-hide-inherited-members/comment-page-1/#comment-25207</link>
		<dc:creator>JeroenH</dc:creator>
		<pubDate>Sun, 17 Jan 2010 18:15:47 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=2181#comment-25207</guid>
		<description>If I were asked to remove one feature from the C# language, it would be the new keyword. There are a few use cases for it, but the potential for errors like you describe is indeed very real.

For an explanation and a few reasonable use cases, see &lt;a href=&quot;http://blogs.msdn.com/ericlippert/archive/2008/05/21/method-hiding-apologia.aspx&quot; rel=&quot;nofollow&quot;&gt;this post on Eric Lippert&#039;s blog&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>If I were asked to remove one feature from the C# language, it would be the new keyword. There are a few use cases for it, but the potential for errors like you describe is indeed very real.</p>
<p>For an explanation and a few reasonable use cases, see <a href="http://blogs.msdn.com/ericlippert/archive/2008/05/21/method-hiding-apologia.aspx" rel="nofollow">this post on Eric Lippert&#8217;s blog</a>.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
