mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 16:58:47 +00:00
Minor refactoring on the observer code.
This commit is contained in:
@@ -28,23 +28,9 @@ public class Weather {
|
||||
}
|
||||
|
||||
public void timePasses() {
|
||||
switch (currentWeather) {
|
||||
case COLD:
|
||||
currentWeather = WeatherType.SUNNY;
|
||||
break;
|
||||
case RAINY:
|
||||
currentWeather = WeatherType.WINDY;
|
||||
break;
|
||||
case SUNNY:
|
||||
currentWeather = WeatherType.RAINY;
|
||||
break;
|
||||
case WINDY:
|
||||
currentWeather = WeatherType.COLD;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
System.out.println("The weather now changes to " + currentWeather);
|
||||
WeatherType[] enumValues = WeatherType.values();
|
||||
currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
|
||||
System.out.println("The weather changed to " + currentWeather + ".");
|
||||
notifyObservers();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user