1:/**
   2: * The TalkerListener "talks" in a space and registers to "listen" to other spaces.
   3: * <br>Observer Design Pattern -- "Gossip" example for COM1204 Summer 2003.
   4: *
   5: * @author Bob Futrelle
   6: * @version 0.1, 28 June 2003
   7: *
   8: */
   9: 
  10: public class TalkerListener {
  11:    
  12:    public String name;
  13:    public Space whereIAmAt;
  14:    
  15:    /** The TalkerListener has a name and a location
  16:    */
  17:    public TalkerListener(String name, Space whereIAmAt){
  18:            this.name = name;
  19:            this.whereIAmAt = whereIAmAt;   
  20:    }
  21:    /** When the TalkerListener speaks, the local space is "notified".
  22:    */
  23:    public void says(String said) {
  24:        whereIAmAt.notifySpace(
  25:            new Message(this,said));    
  26:    }
  27:    
  28:    /** When a space that the TalkerListener has registered with receives
  29:     * a message, it notifies the TalkerListener using this method.
  30:     */
  31:    public void notifyMe(Message msg) {
  32:        // Don't report what you yourself just said.
  33:        if(msg.talkerListener != this) 
  34:        System.out.println(name + " at the " + whereIAmAt.name + " just heard: \n"
  35:        + "\"" + msg.whatTalkerSaid + "\"\nfrom the place, the " +
  36:        msg.talkerListener.whereIAmAt.name + "\n");
  37:    }
  38:    
  39:    /** Tells us the contents of any telepathic message being sent.
  40:    */
  41:    public void transmits(String telepathic) {
  42:        System.out.println("Telepathic message:\n\"" +
  43:        telepathic + "\"");
  44:    }
  45: } // class TalkerListener