Skip to content

Instantly share code, notes, and snippets.

@gayashanbc
Created July 22, 2018 18:46
Show Gist options
  • Save gayashanbc/456b21f2d16f5cab5d2738ab5fa91947 to your computer and use it in GitHub Desktop.
Save gayashanbc/456b21f2d16f5cab5d2738ab5fa91947 to your computer and use it in GitHub Desktop.
Implementation file of the main class (Observer Pattern in C++)
#include <iostream>
#include "WeatherData.hpp"
#include "Client.hpp"
int main() {
WeatherData weatherStation;
Client one(1), two(2), three(3);
float temp, humidity, pressure;
weatherStation.registerObserver(&one);
weatherStation.registerObserver(&two);
weatherStation.registerObserver(&three);
std::cout << "Enter Temperature, Humidity, Pressure (seperated by spaces) << ";
std::cin >> temp >> humidity >> pressure;
weatherStation.setState(temp,humidity,pressure);
weatherStation.removeObserver(&two);
std::cout << "\n\nEnter Temperature, Humidity, Pressure (seperated by spaces) << ";
std::cin >> temp >> humidity >> pressure;
weatherStation.setState(temp,humidity,pressure);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment