Ubuntu 10.10 Pentax K-5

Monday, April 25, 2005

Observation Pattern

Publishers + Subscribers = Observer Pattern

How newspaper or magazine subscription work:
1. A newspaper publisher goes into business and begins publishing newspapers.
2. You subscribe to a particular publisher and every time there's a new edition it gets delivered to you.
3. You unsubscribe when you don't want papers anymore, and they stop being delivered.
4. While the publisher remains in business, people,... constantly subscribe and unsubscribe to the newspaper.

The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.

When two objects are loose coupled, they interact with each other, but they have very little knowledge about each other.

No comments: