Observer Pattern Flashcards

(14 cards)

1
Q

Subject

A

The object being observed; owns the state and notifies observers when it changes.

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

Observer

A

Dependent objects that are interested in changes to the subject’s state.

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

Concrete Subject

A

Implementation of the subject interface; includes state and logic for managing observers.

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

Concrete Observer

A

Implements the observer interface and defines how it reacts to changes in the subject.

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

notifyObservers()

A

Called by the subject to update all registered observers.

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

update()

A

Called by the subject on each observer to notify them of a state change.

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

registerObserver(o)

A

Adds an observer to the subject’s list.

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

removeObserver(o)

A

Removes an observer from the subject’s list.

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

Observer Pattern

A

A behavioural design pattern where a subject (publisher) maintains a list of observers (subscribers) and notifies them automatically of any state changes.

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

Observer Pattern Structure

A

Classes:
- Subject Interface
- Concrete Subject
- Observer Interface
- Concrete Observer

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

Subject Interface (Observer Pattern Classes)

A
  • Methods: registerObserver(), removeObserver(), notifyObservers()
  • Maintains a list of observers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Concrete Subject (Observer Pattern Classes)

A
  • Stores actual state (e.g. weather data or clock time).
  • Implements methods from Subject interface.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Observer Interface (Observer Pattern Classes)

A

Declares update() method.

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

Concrete Observer (Observer Pattern Classes)

A
  • Has its own state.
  • Implements update() to stay consistent with the subject.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly