securityzone.java~7~

来自「《深入浅出设计模式》的完整源代码」· JAVA~7~ 代码 · 共 45 行

JAVA~7~
45
字号
package securitysystem;

public abstract class SecurityZone {
  private SecurityZone parent;
  public String name;
  public SecurityZone(String name)
  {
    this.name=name;
  }


  //Return this object's parent zone.
    SecurityZone getParent() {
        return parent;
    } // getParent()
    /**
         * Call this method to notify this zone of a new sensor
         * measurement.
         */
    void notify(int measurement, Sensor sensor) {
        if (!handleNotification (measurement, sensor)&& parent != null) {
            parent.notify (measurement, sensor);
          } // if
     }
     /**
     * This method is called by the notify method so that
     * this object can have a chance to handle measurements.
     */
    abstract boolean handleNotification(int measurement,
                                        Sensor sensor);
    /**
    * This method is called by a child zone to report a fire.
    * It is expected that the child zone has turned on
    * sprinklers or taken other measures to control the fire
    * within the child zone. The purpose of this method is to
    * be overridden by subclasses so it can take any
    * necessary actions outside of the child zone.
    */
   void fireAlarm(SecurityZone zone) {
       // Turn on sprinklers
       System.out.println(this.name+"true on the sprinkles in"+zone.name);
       if (parent != null)
         parent.fireAlarm(zone);
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?