Objective:
In this assignment, you will implement the Observer Design Pattern to simulate a Weather Station. You will design a system where weather data (such as temperature, humidity, and pressure) is monitored by a central weather station, and different displays or systems (observers) are updated automatically when the weather data changes.
Problem Statement:
You are tasked with building a Weather Station system using the Observer Design Pattern. The system should consist of the following components:
- Subject (WeatherStation): This class will maintain the weather data (temperature, humidity, and pressure) and notify all registered observers whenever the weather data changes.
- Observer (Display): Multiple observers can subscribe to the weather station to receive updates about changes in the weather. Each observer will implement a method to update and display the weather data when notified by the subject.
- Concrete Observers: Implement at least two different types of displays as concrete observers that show different aspects of the weather data, such as:
-
- CurrentConditionsDisplay: This display shows the current temperature and humidity.
- StatisticsDisplay: This display shows the most recent temperature and humidity.
Requirements:
- Observer Interface: Create an abstract Observer class with an update method. This method will be called by the WeatherStation whenever the weather data is updated.
- Weather Station (Subject):
- The WeatherStation class should store the weather data (temperature, humidity, and pressure).
- It should be able to register, remove, and notify observers whenever the weather data changes.
- Create a method set_weather_data() to update the weather data and notify all observers.
- Display (Observer):
- Implement at least two types of concrete observers: CurrentConditionsDisplay and StatisticsDisplay.
- Each display should implement the update method to handle weather data updates and display the data appropriately.
- Program Execution:
-
- Instantiate the WeatherStation and create multiple observers.
- Update the weather data using the set_weather_data() method and verify that all observers are notified with the updated information.
Example Execution:
Current conditions: 25.3°C and 65% humidity. Statistics: Temperature: 25.3°C, Humidity: 65% Current conditions: 28.1°C and 70% humidity. Statistics: Temperature: 28.1°C, Humidity: 70%
Deliverables:
- Submit the code that implements the weather station system using the Observer Design Pattern.
- Provide a brief description of how the Observer Design Pattern is applied in this system and how it benefits the design of the weather station.
Evaluation Criteria:
- Correct implementation of the Observer Design Pattern.
- Proper usage of object-oriented principles such as inheritance, abstraction, and encapsulation.
- Correct implementation of the update method in the observers.
Proper functioning of the system where observers receive updates when the weather data changes.