Observer Pattern Code Review

Use the Observer Pattern

Code Review

Code Walkthrough

The Program class creates the Subject object, which in turn invokes the Simulator object where events are set up that can be subscribed to.

class Program { static void Main(string[] args) { Subject subject = new Subject(); Observer observer = new Observer(subject, "Thabo"); Observer observer2 = new Observer(subject, "Ellen"); subject.Go(); } }

The Observer objects are created and automatically subscribe to all the available events. The Go() method will raise the appropriate events, and each Observer will in turn be notified.