Exam 2 - L17 - Observer Design Pattern Flashcards

1
Q

What is the main purpose of the Observer Design pattern?

A

To allow multiple objects (observers) to automatically respond to changes in another object (subject/publisher), promoting loose coupling.

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

What is loose coupling?

A

Classes have few dependencies

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

What are the key components in the Observer Pattern?

A

Subject (Publisher) - Maintains list of observers, provides attach/detach/notify methods.

Observer (Subscriber) - Interface that defines the update() method.

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

What does the subscription mechanism involve?

A
  1. A list to store subscribers
  2. Public methods to add/remove subscribers
  3. A ‘notifyObservers()’ method to call each observer’s ‘update()’ method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the advantages of using the Observer Pattern?

A

Loose coupling

Reusability and modularity

Broadcasting capability to multiple observers

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

What are some potential downsides of the Observer Pattern?

A

Memory leaks (if observers aren’t detached)

Implementation complexity

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