Exemple #1
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentDisplay    = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay   = new ForecastDisplay(weatherData);
            HeatIndexDisplay         heatIndexDisplay  = new HeatIndexDisplay(weatherData);

            Measurements measurements = new Measurements
            {
                humidity    = 65F,
                pressure    = 30.4F,
                temperature = 80F
            };

            weatherData.SetMeasurements(measurements);

            measurements.humidity    = 70F;
            measurements.pressure    = 29.2F;
            measurements.temperature = 82F;
            weatherData.SetMeasurements(measurements);

            measurements.humidity    = 90F;
            measurements.pressure    = 29.2F;
            measurements.temperature = 78F;
            weatherData.SetMeasurements(measurements);
        }
        static void Main()
        {
            WeatherData wd = new WeatherData();
            CurrentConditionsDisplay ccd = new CurrentConditionsDisplay(wd);
            StatisticsDisplay sd = new StatisticsDisplay(wd);
            HeatIndexDisplay hid = new HeatIndexDisplay(wd);

            wd.SetMeasurements(78, 90, 29.2f);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentDisplay    = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay   = new ForecastDisplay(weatherData);
            HeatIndexDisplay         heatIndexDisplay  = new HeatIndexDisplay(weatherData);

            weatherData.setMeasurements(80, 65, 30.4f);
            weatherData.setMeasurements(82, 70, 29.2f);
            weatherData.setMeasurements(78, 90, 29.2f);
        }
Exemple #4
0
        public void Main()
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay        = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay          = new ForecastDisplay(weatherData);
            HeatIndexDisplay         heatIndexDisplay         = new HeatIndexDisplay(weatherData);

            weatherData.SetMeasurementsChanged(80, 65, 30.4f);
            Console.WriteLine("===========================================");
            weatherData.SetMeasurementsChanged(82, 70, 29.2f);
            Console.WriteLine("===========================================");
            weatherData.SetMeasurementsChanged(78, 90, 29.2f);
        }
Exemple #5
0
        static void Main()
        {
            // First example
            ConcreteSubject s = new ConcreteSubject();
            s.Attach(new ConcreteObserver(s, "x"));
            s.Attach(new ConcreteObserver(s, "y"));
            s.Attach(new ConcreteObserver(s, "z"));
            s.SubjectState = "abc";
            s.Notify();

            IBM ibm = new IBM("IBM", 120.00);
            ibm.Attach(new Investor("Sorros"));
            ibm.Attach(new Investor("Berkshire"));

            ibm.Price = 120.10;
            ibm.Price = 121.00;
            ibm.Price = 120.50;
            ibm.Price = 120.75;
            ibm.Notify();

            // Second example
            BaggageHandler provider = new BaggageHandler();
            ArrivalsMonitor observer1 = new ArrivalsMonitor("BaggageClaimMonitor1");
            ArrivalsMonitor observer2 = new ArrivalsMonitor("SecurityExit");

            provider.BaggageStatus(712, "Detroit", 3);
            observer1.Subscribe(provider);
            provider.BaggageStatus(712, "Kalamazoo", 3);
            provider.BaggageStatus(400, "New York-Kennedy", 1);
            provider.BaggageStatus(712, "Detroit", 3);
            observer2.Subscribe(provider);
            provider.BaggageStatus(511, "San Francisco", 2);
            provider.BaggageStatus(712);
            observer2.Unsubscribe();
            provider.BaggageStatus(400);
            provider.LastBaggageClaimed();

            // Third example
            var weatherData = new WeatherData();
            var forecastDisplay = new ForecastDisplay(weatherData);
            var heatIndexDisplay = new HeatIndexDisplay(weatherData);
            weatherData.setMeasurements(80, 65, 30.4f);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Weather Station");
            Console.WriteLine();

            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentDisplay    = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay   = new ForecastDisplay(weatherData);
            HeatIndexDisplay         heatIndexDisplay  = new HeatIndexDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            Console.WriteLine();
            weatherData.SetMeasurements(87, 70, 29.2f);
            Console.WriteLine();
            weatherData.SetMeasurements(78, 90, 29.2f);
            Console.WriteLine();
            weatherData.SetMeasurements(65, 75, 29.2f);
            Console.WriteLine();

            int   temp, hum;
            float press;

            Console.Write("What is the current Temperature? T: ");
            temp = Int32.Parse(Console.ReadLine());
            Console.Write("What is the current Humidity? H: ");
            hum = Int32.Parse(Console.ReadLine());
            Console.Write("What is the current Pressure? P: ");
            press = float.Parse(Console.ReadLine());
            Console.WriteLine();

            weatherData.SetMeasurements(temp, hum, press);
            Console.WriteLine();

            Console.ReadKey();
        }