- 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.
推薦閱讀
- 大規(guī)模數(shù)據(jù)分析和建模:基于Spark與R
- Voice Application Development for Android
- 商業(yè)分析思維與實(shí)踐:用數(shù)據(jù)分析解決商業(yè)問(wèn)題
- Apache Kylin權(quán)威指南
- Splunk智能運(yùn)維實(shí)戰(zhàn)
- 數(shù)據(jù)庫(kù)原理與應(yīng)用
- Hadoop 3實(shí)戰(zhàn)指南
- R Object-oriented Programming
- 菜鳥(niǎo)學(xué)SPSS數(shù)據(jù)分析
- 大數(shù)據(jù)技術(shù)原理與應(yīng)用:概念、存儲(chǔ)、處理、分析與應(yīng)用
- The Natural Language Processing Workshop
- 數(shù)據(jù)挖掘競(jìng)賽實(shí)戰(zhàn):方法與案例
- 算法設(shè)計(jì)與分析
- 代碼的未來(lái)
- Learn Selenium