- Hands-On Design Patterns with Java
- Dr. Edward Lavieri
- 140字
- 2021-06-24 14:58:06
Slider-related methods
The final section of the ControlBox class provides methods to increase or decrease the slider value. It is important to check two things when adjusting the slider value. First, we need to ensure the power is on. We can check that by making a call to our hasPower() method. The second check is to ensure we do not go outside the minimum-maximum range, as follows:
// Method to increase slider value
public void sliderIncrease () {
if (hasPower()) {
if (getSliderValue() < SLIDER_MAX) {
sliderValue++;
System.out.println(sliderValue); // simulate sending value to digital display
}
}
}
// Method to decrease slider value
public void sliderDecrease () {
if (hasPower()) {
if (getSliderValue() > SLIDER_MIN) {
sliderValue--;
System.out.println(sliderValue); // simulate sending value to digital display
}
}
}
}
The slider value can be used to manage temperature, volume, quantity, or other values based on what system the control box is integrated with. This demonstrates the command pattern.
This section featured the source code that demonstrates the command design pattern.
推薦閱讀
- 大規模數據分析和建模:基于Spark與R
- 數據產品經理高效學習手冊:產品設計、技術常識與機器學習
- 云數據中心基礎
- Python數據挖掘:入門、進階與實用案例分析
- Visual Studio 2015 Cookbook(Second Edition)
- 從0到1:JavaScript 快速上手
- 高維數據分析預處理技術
- SQL應用及誤區分析
- Hadoop大數據開發案例教程與項目實戰(在線實驗+在線自測)
- 探索新型智庫發展之路:藍迪國際智庫報告·2015(上冊)
- 數據分析師養成寶典
- 離線和實時大數據開發實戰
- 從Lucene到Elasticsearch:全文檢索實戰
- 數據挖掘算法實踐與案例詳解
- 數據庫原理及應用:SQL Server 2016