P
Peter Duniho
Okay, this has come up in the past but I haven't seen anything that I
would call a good, solid general rule.
The question applies more generally, but I'm going to ask in the context
of a Control. How does one decide whether to write an "override" method
to an event and when to simply add an event handler for that event?
For example, you can either write a new OnPaint override, or you can
register a delegate that the Control's base OnPaint method will execute.
My current thought is that when you are not inheriting from the base
class, you register a delegate (duh, since you obviously have no way to
override the method in that case), and when you are inheriting from the
base class, you override the method (the main reason here being that if
you're inheriting from the base class, you want your new functionality to
always work, rather than relying on your delegate remaining in the event
handler list).
In other words, override when you can, add an event handler if you can't.
Is it really as simple as that? Or are there other factors I should be
considering?
Many thanks in advance for the wisdom of those who have gone down this
road before me.
Pete
would call a good, solid general rule.
The question applies more generally, but I'm going to ask in the context
of a Control. How does one decide whether to write an "override" method
to an event and when to simply add an event handler for that event?
For example, you can either write a new OnPaint override, or you can
register a delegate that the Control's base OnPaint method will execute.
My current thought is that when you are not inheriting from the base
class, you register a delegate (duh, since you obviously have no way to
override the method in that case), and when you are inheriting from the
base class, you override the method (the main reason here being that if
you're inheriting from the base class, you want your new functionality to
always work, rather than relying on your delegate remaining in the event
handler list).
In other words, override when you can, add an event handler if you can't.
Is it really as simple as that? Or are there other factors I should be
considering?
Many thanks in advance for the wisdom of those who have gone down this
road before me.
Pete