Method Replacement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I know that C# supports VB's concept of 'Shadows' via "method replacement"
and the keyword "new". Is this considered a good practice? - It seems like
you might be breaking a class's contract if you use method replacement? Any
input is welcome...

--Richard
 
Richard said:
I know that C# supports VB's concept of 'Shadows' via "method replacement"
and the keyword "new". Is this considered a good practice? - It seems like
you might be breaking a class's contract if you use method replacement? Any
input is welcome...

It's not breaking a class's contract, but it's not generally a good
idea. It makes the calling code much harder to understand, usually.
It's good to have it for the rare situation where a new method is added
to a base class and it conflicts with a method in an older version of a
derived class. The users of the derived class still want the old method
to be available, but they don't want it to override the new method from
the base class. At that point, making it a "new" method works quite
well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top