Creating an event system in C# to tie things together loosely
We won’t need a UML diagram here as the design is quite simple. We’ll use a Dictionary
collection (a special kind of C# collection) to hold the name of an event that we’ll assign the event’s callback handlers. The added callback handlers will all be invoked when the event is triggered. Although I say this is simple, I didn’t introduce it earlier because a few programming concepts still needed to be covered first.
The new event system
Since a UML diagram won’t illustrate the functionality of EventSystem
very well in this case, I’ve decided to create the following diagram as an introduction to the implementation (see Figure 9.1):
Figure 9.1 – EventSystem diagram
Before looking at the following code, do a quick mental exercise to see if you can visualize what the code should look like from this diagram.
Given this diagram, here is...