- Hands-On Design Patterns with Java
- Dr. Edward Lavieri
- 124字
- 2021-06-24 14:58:10
Starter
The Starter class includes two class variables, a constructor method, an accessor method, and two methods that toggle the starter on and off. The constructor is used to instantiate copies of the class. The accessor method simply returns the value of the poweredOn variable:
public class Starter {
private WidgetProductionSystem mediator;
private boolean poweredOn;
// Constructor
public Starter(WidgetProductionSystem mediator) {
this.mediator = mediator;
poweredOn = false;
mediator.mediateStarter(this);
}
// accessor
public boolean isSystemOn() {
return poweredOn;
}
public void turnOn() {
poweredOn = true;
mediator.starterPoweredOn();
System.out.println("Mediated Event: Started Powered On");
}
public void turnOff() {
poweredOn = false;
mediator.starterPoweredOff();
System.out.println("Mediated Event: Starter Powered Off");
}
}
Also provided are the turnOn() and turnOff() methods, which simply toggle the value of the powerOn variable.
推薦閱讀
- Spark大數據分析實戰
- Access 2016數據庫技術及應用
- 大數據架構和算法實現之路:電商系統的技術實戰
- Hadoop 3.x大數據開發實戰
- MATLAB Graphics and Data Visualization Cookbook
- 大數據技術入門
- 云原生數據中臺:架構、方法論與實踐
- 從實踐中學習sqlmap數據庫注入測試
- The Natural Language Processing Workshop
- Hands-On System Programming with C++
- Deep Learning with R for Beginners
- Unity Game Development Blueprints
- Kubernetes快速進階與實戰
- 碼上行動:利用Python與ChatGPT高效搞定Excel數據分析
- 代碼的未來