- 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.
推薦閱讀
- Java Data Science Cookbook
- 正則表達式必知必會
- MySQL從入門到精通(第3版)
- Learning JavaScriptMVC
- Live Longer with AI
- 軟件成本度量國家標準實施指南:理論、方法與實踐
- Unreal Engine Virtual Reality Quick Start Guide
- Visual FoxPro數據庫技術基礎
- 數據庫查詢優化器的藝術:原理解析與SQL性能優化
- 數據應用工程:方法論與實踐
- 精通Neo4j
- SQL進階教程(第2版)
- MySQL核心技術手冊
- Nagios Core Administrators Cookbook
- Getting Started with Review Board