- 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.
推薦閱讀
- Google Visualization API Essentials
- SQL Server入門經典
- Test-Driven Development with Mockito
- 大數據可視化
- 新型數據庫系統:原理、架構與實踐
- SQL查詢:從入門到實踐(第4版)
- 大數據Hadoop 3.X分布式處理實戰
- Proxmox VE超融合集群實踐真傳
- Python數據分析與挖掘實戰(第3版)
- 區域云計算和大數據產業發展:浙江樣板
- R Object-oriented Programming
- 企業大數據處理:Spark、Druid、Flume與Kafka應用實踐
- Artificial Intelligence for Big Data
- 碼上行動:利用Python與ChatGPT高效搞定Excel數據分析
- NoSQL數據庫原理(第2版·微課版)