Brain Dump

Observer Pattern

Tags
soft-eng

Is a software design pattern where an object (the subject) maintains a list of its dependants (called observers) that are automatically notified of state changes by calling one of their methods.

This pattern registers objects for callbacks [see page 24, indicating] late design fixes.

\begin{figure}
  \centering
  \begin{tikzpicture}
    \umlclass{Subject}{}{add(Observer) \\ remove(Observer) \\ notifyObservers()}
    \umlclass[x=6cm]{Observer}{}{notify()}
    \umlclass[x=4cm, y=-3cm]{ObserverA}{}{notify()}
    \umlclass[x=8cm, y=-3cm]{ObserverB}{}{notify()}

     \umlnote[y=-3cm]{Subject}{forall o in observers: o.notify()}

     \umlVHVinherit{ObserverA}{Observer}
     \umlVHVinherit{ObserverB}{Observer}
     \umlaggreg[attr2=observers|0..*, pos=0.7]{Subject}{Observer}
  \end{tikzpicture}
  \caption{The observer pattern.}
\end{figure}