Observer Pattern Code Review
Use the Observer Pattern
Code Review
- Observer Pattern Code Review: Define the Pattern Interface and Handler Object
- Observer Pattern Code Review: Define the Subject, Blogs and Simulator Objects
- Observer Pattern Code Review: Define the Windows Form Graphical User Interface
- Observer Pattern Code Review: Use the Observer Pattern
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.
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!