001package headfirst.combining.observer; 002 003import java.util.ArrayList; 004import java.util.Iterator; 005 006public class Observable implements QuackObservable { 007 ArrayList<Observer> observers = new ArrayList<Observer>(); 008 QuackObservable duck; 009 010 public Observable(QuackObservable duck) { 011 this.duck = duck; 012 } 013 014 public void registerObserver(Observer observer) { 015 observers.add(observer); 016 } 017 018 public void notifyObservers() { 019 for (Observer observer : observers) { 020 observer.update(duck); 021 } 022 } 023 024 @SuppressWarnings("rawtypes") 025 public Iterator getObservers() { 026 return observers.iterator(); 027 } 028}