Observer Pattern in C# using Delegates and Events
Spanish version / Versión en Español In C++, the Observer design pattern (also known as Publisher/Subscriber) is usually implemented as suggested in the bible of design patterns . This implementation requires that Observer and Observed implement the IObserver and IObserved interfaces, so that when Observed changes, all its registered Observers are notified. Needless to say, this can be done the same way in C#. However, this is not necessary since the Observer pattern is implemented in the C# language itself, with its delegates and events constructs. Suppose we want to use this to implement the MVC architecture pattern in our C# application. The MVC rationale says that View objects can reference Model objects, but not the other way around. So how does the model communicate with the view? Using the Observer Pattern. First, in our Model class, we must declare the Event which will be triggered when the Model changes. Then, we must define the delegate associated to this e...