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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

AKA

A

Dependents, Publish-Subscribe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Motivation

A

To maintain consistency between related objects’ states without tight coupling.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Key Objects

A

Subject and Observer

Observer will query the subject to synchronize its state with the subject’s state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Structure

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Related Patterns

A

Mediator and Singleton

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Who maintains a reference to subject?

A

ConcreteObserver

How well did you know this?
1
Not at all
2
3
4
5
Perfectly