Designing Events for Use by Derived Classes

What about extenders of our CountDown type? Assume we’ve designed our countdown mechanism such that its core functionality can be overridden (for example, by marking Start as virtual) or we simply haven’t sealed the class. The subtype might want to raise any of our events as part of its extension. For example, a CountDown with an EmergencyStop facility might want to call Finished before the timer reaches zero. I invite you to think about more examples.

The key question is whether a subtype can raise an event declared on its base type. A little bit of reasoning can help answer this question without having to loop in the compiler just yet. You’ve seen how an event declaration leads to the creation of ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.