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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.