⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 securityzone.java~3~

📁 《深入浅出设计模式》的完整源代码
💻 JAVA~3~
字号:
package securitysystem;

public abstract class SecurityZone {
  private SecurityZone parent;
  private String name;
  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.toString()+"true on the sprinkles in"+zone.toString());
       if (parent != null)
         parent.fireAlarm(zone);
   }
}

⌨️ 快捷键说明

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