Exemplo n.º 1
0
        static void Main(string[] args)
        {
            /*
             * each observer can set customized temperature and pressure alert levels;
             * observer is notified each time the weather data changes and is being sent extra alerts based on own
             * temperature and pressure alert levels
             */

            WeatherStation weatherStation = new WeatherStation();

            weatherStation.Add(new Observer(weatherStation, "Observer 1", -15, 30, 1000, 1050));
            weatherStation.Add(new Observer(weatherStation, "Observer 2", 0, 25, 1010, 1040));

            weatherStation.Notify();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            WeatherStation station = new WeatherStation();

            station.Subscribe(new Gismeteo());
            station.Subscribe(new StreetWeatherStand());
            station.Subscribe(new WeatherForecast());

            station.Notify(new WeatherInfo()
            {
                Temperature = 30, WindSpeed = 2
            });
            Console.WriteLine("----------------------------------------------------\n");
            station.Notify(new WeatherInfo()
            {
                Temperature = -5, WindSpeed = 12
            });
        }
Exemplo n.º 3
0
        public static void TestRun()
        {
            WeatherStation weatherStation = new WeatherStation();

            NewsAgency agency1 = new NewsAgency("Alpha News Agency");

            weatherStation.Attach(agency1);

            NewsAgency agency2 = new NewsAgency("Omega News Agency");

            weatherStation.Attach(agency2);


            weatherStation.Temperature = 31.2f;
            weatherStation.Temperature = 28.5f;
            weatherStation.Temperature = 33.1f;
            weatherStation.Temperature = 29.2f;

            Console.ReadLine();
        }
Exemplo n.º 4
0
        private static void RunWeatherDemo()
        {
            WeatherSubject  subject   = new WeatherStation(16);
            WeatherObserver observer  = new HomeThermostat();
            WeatherObserver observer2 = new HomeThermostat();


            WeatherObserver auto = new Car(130, 45);

            subject.AddObserver(observer);
            subject.AddObserver(observer2);
            subject.AddObserver(auto);



            (subject as WeatherStation).SetTemperature(10);
            Console.WriteLine(auto.ToString());
            (subject as WeatherStation).SetTemperature(4);
            Console.WriteLine(auto.ToString());
            (subject as WeatherStation).SetTemperature(30);
            Console.WriteLine(auto.ToString());
        }