Observer Pattern

Classification: Behavioral patterns
Description : Define a one-to-many dependency between objects where a state change in one object results in all its dependents being notified and updated automatically.

This pattern is sometimes referred to as Listeners in some frameworks.

Read about the pattern here.
The code sample can be found in my git repo.

In the example code I have done, there is a city, as with all cities many things can go wrong in a city. So city is the subject or the observable. To handle the emergency situations we have many emergency handlers. These handlers observe the city and take actions when needed. So handlers are Observers.
When something happens in the city, all observers will be notified. Some observers respond to the situation and some do not.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s