// 观察者定义 publicinterfaceWeatherObserver{ voidupdate(WeatherType currentWeather); } // 观察者——霍比特人 publicclassHobbitsimplementsWeatherObserver{ privatestaticfinal Logger LOGGER = LoggerFactory.getLogger(Hobbits.class); @Override publicvoidupdate(WeatherType currentWeather){ switch (currentWeather) { case COLD: LOGGER.info("The hobbits are shivering in the cold weather."); break; case RAINY: LOGGER.info("The hobbits look for cover from the rain."); break; case SUNNY: LOGGER.info("The happy hobbits bade in the warm sun."); break; case WINDY: LOGGER.info("The hobbits hold their hats tightly in the windy weather."); break; default: break; } } } // 观察者——兽人 publicclassOrcsimplementsWeatherObserver{ privatestaticfinal Logger LOGGER = LoggerFactory.getLogger(Orcs.class); @Override publicvoidupdate(WeatherType currentWeather){ switch (currentWeather) { case COLD: LOGGER.info("The orcs are freezing cold."); break; case RAINY: LOGGER.info("The orcs are dripping wet."); break; case SUNNY: LOGGER.info("The sun hurts the orcs' eyes."); break; case WINDY: LOGGER.info("The orc smell almost vanishes in the wind."); break; default: break; } } }