warehouse.java~16~
来自「《深入浅出设计模式》的完整源代码」· JAVA~16~ 代码 · 共 36 行
JAVA~16~
36 行
package securitysystem;public class Warehouse extends SecurityZone{ /** * This method is called by the notify method so that this * object can have a chance to handle measurements. */ boolean handleNotification(int measurement, Sensor sensor) { if (sensor instanceof TemperatureSensor) { if (measurement > 200) { fireAlarm(this,sensor); return true; } } return false; } // handleNotification(int, Sensor) void fireAlarm(SecurityZone zone,Sensor sensor) { if (zone instanceof Area) { // Turn on sprinklers in surrounding areas // Don't call super.fireAlarm because that will turn on the // sprinkler for the whole warehouse. System.out.println("保安请马上去检查"+this.name+"的"+zone.name); if (getParent() != null) getParent().fireAlarm(zone,sensor); return; } // if super.fireAlarm(zone,sensor); } // fireAlarm(SecurityZone) public Warehouse(String string) { super(string); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?