For people new to OO and polymorphism it is difficult to grasp (believe me I teach alot of people C# from non-OO backgrounds). The problem with new virtual is you have to know the details of every class in derivation chain to understand what is going to happen when you call a method through the base class - this to me is bad. If I override a method from the bottom of my derivation chain and then find a different version is being called - where do I start to look? Once you know about the evils of new virtual you may look in the inheritance chain and see someone has used new virtual.
How about if I write a class that does this:
class Foo
{
public new virtual string ToString()
{
return string.Empty;
}
}
ugghhhh. now when any derived class object is passed to Console.WriteLine it will print out a blank - isn;t that an obvious behavior.
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
"Richard Blewett [DevelopMentor]" <ri******@NOSPAMdevelop.com> wrote in
news:Od**************@TK2MSFTNGP15.phx.gbl:
new virtual is the spawn of Satan.
Your example is nice... however I think you are making it sound like a
difficult concept to grasp.
The 'new' keyword simply identifies the point at which overridden functions
become "invisible" when called from objects declared as a base type of the
class in question. The 'virtual' keyword indicates that a function might
be overridden in derived classes and that objects should try to use the
most overridden function possible.
There's nothing conflicting between these two concepts, as long as one
understands that 'invisible' is not 'possible'.
-mdb