\begin{slide}{Verhaltensmuster: Beobachter}

\begin{itemize}\itemsep 0pt
\item Subjekt: class Observable
\begin{itemize}\itemsep 0pt
\item anmelden: void addObserver (Observer o)
\item abmelden: void deleteObserver (Observer o)
\item Zustandsänderung: void setChanged ()
\item Benachrichtigung: void notifyObservers(\dots)
\end{itemize}
\item Beobachter: interface Observer
\begin{itemize}\itemsep 0pt
\item aktualisiere: void update (\dots)
\end{itemize}
\end{itemize}


\end{slide}

\begin{slide}{Beobachter: Beispiel}

\begin{verbatim}
public class Counter extends Observable {
    private int count = 0;
    public void step () { this.count ++;
        this.setChanged(); 
        this.notifyObservers();   }   }
public class Watcher implements Observer {
    private final int threshold;
    public void update(Observable o, Object arg) {
       if (((Counter)o).getCount() >= this.threshold) {
           System.out.println ("alarm");  }   }  }
public static void main(String[] args) {
    Counter c = new Counter (); Watcher w = new Watcher (3);
    c.addObserver(w); c.step(); c.step (); c.step (); }
\end{verbatim}
  
\end{slide}

