Observer Flashcards
1
Q
Intent
A
Define a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated.
2
Q
AKA
A
Dependents, Publish-Subscribe
3
Q
Motivation
A
To maintain consistency between related objects’ states without tight coupling.
4
Q
Key Objects
A
Subject and Observer
Observer will query the subject to synchronize its state with the subject’s state.
5
Q
Structure
A
6
Q
Participants
A
- Subject
- knows its observers
- provides an interface for attaching and deataching Observer objects
- Observer
- defines an updating interface
- ConcreteSubject
- stores subscribed observers
- notifies observers when state changes
- ConcreteObserver
- maintains a reference to a ConcreteSubject
- stores state that reflects the subject’s state
- implements Observer’s update
7
Q
Related Patterns
A
Mediator and Singleton
8
Q
Who maintains a reference to subject?
A
ConcreteObserver