1:import java.util.*;
   2:
   3:/**
   4: * The Space class where messages are sent and which notifies registered listeners.
   5: * <br>Observer Design Pattern -- "Gossip" example for COM1204 Summer 2003.
   6: *
   7: * @author Bob Futrelle
   8: * @version 0.1, 28 June 2003
   9: *
  10: */
  11: public class Space {
  12:    
  13:    public String name;
  14:    public ArrayList registeredListeners;
  15:    
  16:    public Space(String name){ 
  17:            this.name = name;
  18:            registeredListeners = new ArrayList();          
  19:    }
  20:    
  21:    /** Allows a TalkerListener to be placed on the registered listeners list.
  22:    */
  23:    public void iCanHearThere(TalkerListener listener) {
  24:            registeredListeners.add(listener);
  25:    }
  26:    /** When a TalkerListener says something, its local space is informed.
  27:    */
  28:    public void notifySpace(Message msg) {
  29:        Iterator listeners = registeredListeners.iterator();
  30:        while(listeners.hasNext()){
  31:            ((TalkerListener)listeners.next()).notifyMe(msg);
  32:            }       
  33:    }   
  34:
  35: } // class Space