Sometimes I override methods in base classes. Sometimes I even override them with an empty method, because what I want is to prevent the behavior.
In the past I would write something like this to show the intent of bypassing the base method:
protected override void OnMouseUp(MouseEventArgs e)
{
// base.OnMouseUp(e);
}
(I know a commented line of code is a bad thing. I used to do it)
But I want to do better:
- How do I document the intention of the override? specifically:
- What do I write in the override’s XML (
<summary>?) documentation?
A comment like
is much better than
The first comment clearly states why you did what you did, and the next developer who comes along won’t have to wonder if the call to the base method was commented out accidentally.
If you have control over the base class, it may be better to remove that method and make the class more abstract. Then you can choose to only implement that functionality in child classes where it’s needed.