Advantages
(+)
-
Decouples subject from observers.
-
Subject only refers to and knows about
the simple
Observer interface
for updating (synchronizing) state (update()).
- "Because Subject and Observer aren't
tightly coupled,
they can belong to different layers of abstraction
in a system.
[GoF, p296]
-
Loosely coupled objects
are easier to implement, change, test, and reuse.
-
Makes adding/withdrawing observers easy.
-
Observers can be added to
(
attach(o)) and withdrawn from
a subject independently and dynamically.
-
Usually, observers are responsible for
registering and unregistering
themselves on a subject.
-
Subject's sole responsibility is
to hold a list of observers
and notify (call
update() on)
them
when its state changes.
Disadvantages
(–)
-
Can make the update behavior complex.
-
A change on the subject
may cause a cascade of updates
to observers
and their dependent objects.
-
The Mediator design pattern can be applied
to implement a complex dependency relationship
between
subject(s) and observers.