When developing a derived class, are there any advantages [] for adding a handler to the base class event ctorversus overriding the method OnEventName()and adding some behavior (as well as calling the base method) if you do not need to change the base method and do not care in what order the events occur, but only wants to use a reusable component with a little extra behavior?
base class:
public abstract class BaseClass
{
public event EventHandler SomeEvent;
protected void OnSomeEvent(object sender, EventArgs e)
{
}
}
option A:
public class DerivedA
{
protected override void OnSomeEvent(object sender, EventArgs e)
{
base.OnSomeEvent(sender, e);
}
}
option B:
public class DerivedB
{
public DerivedB()
{
SomeEvent += (o,e) => { // do some other stuff };
}
}
source
share