Observer: Watching and Listening
Observer Players
This pattern brings the following players to the stage:
- Subject: the object that keeps a list of Observers and notifies them of new events.
- Observer: an object that registers with a Subject to receive notifications of new events/information from a Subject.
- Stimulus: the source of the event that a Subject sends to its Observers. A Subject itself may be the Stimulus.
Pushing an event or new information to Observers is
the most common implementation for this pattern.
A Subject maintains a list of Observers, including methods to add and optionally remove Observers.When a Stimulus is received (or when the Subject produces its own stimulus), the Subject
notifies all Observers about the new information.
Observers pull events or new information from Subjects
when it is expensive to push that information to all Observers.
(Reading...)
Formatting Hints:
To format... | use this markup: |
---|---|
source code | {source:lang=java|lineNumbers=false}...{source} (Supported languages: java, cpp, csharp, c, python.) |
bold text | __some text__ |
italicized text | ~~some text~~ |
underlined text | @@some text@@ |
a method or class name | ``myMethod(...)`` |