Information Technology Reference
In-Depth Information
// details elided.
}
}
This is a problem. Your base class snuck a method underneath your class's
naming scope. There are two ways to fix this. You could change that
name of your NormalizeValues method. Note that I've implied that
BaseWidget.NormalizeValues() is semantically the same operation as
MyWidget.NormalizeAllValues. If not, you should not call the base class
implementation.
public class MyWidget : BaseWidget
{
public void NormalizeAllValues()
{
// details elided.
// Call the base class only if (by luck)
// the new method does the same operation.
base .NormalizeValues();
}
}
Or, you could use the new modifier:
public class MyWidget : BaseWidget
{
public void new NormalizeValues()
{
// details elided.
// Call the base class only if (by luck)
// the new method does the same operation.
base .NormalizeValues();
}
}
If you have access to the source for all clients of the MyWidget class, you
should change the method name because it's easier in the long run. How-
ever, if you have released your MyWidget class to the world, that would force
all your users to make numerous changes. That's where the new modifier
comes in handy. Your clients will continue to use your NormalizeValues()
method without changing. None of them would be calling BaseWidget
.NormalizeValues () because it did not exist. The new modifier handles the
Search WWH ::




Custom Search