コード例 #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);

            // create the readings
            WeatherMeasurements readings = new WeatherMeasurements();

            readings.Temperature = 80f;
            readings.Humidity    = 65f;
            readings.Pressure    = 30.4f;

            weatherData.Mesurements(readings);

            readings.Temperature = 82f;
            readings.Humidity    = 70f;
            readings.Pressure    = 29.2f;
            weatherData.Mesurements(readings);

            readings.Temperature = 78f;
            readings.Humidity    = 90f;
            weatherData.Mesurements(readings);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ashleyo/SharperC
        static void Main(string[] args)
        {
            WeatherData WD = new WeatherData();
            CurrentConditionsDisplay CCdisplay = new CurrentConditionsDisplay(WD);
            StatisticalDisplay STDisplay = new StatisticalDisplay(WD);
            WD.setMeasurements(15.4f, 65.2f, 1002f);
            WD.setMeasurements(15.6f, 64.0f, 1004f);
            WD.setMeasurements(15.7f, 63.8f, 1004f);
            WD.setMeasurements(15.7f, 63.2f, 1004f);
            WD.setMeasurements(15.8f, 63.4f, 1003f);
            WD.setMeasurements(15.8f, 63.3f, 1004f);
            WD.setMeasurements(15.8f, 63.3f, 1004f);
            WD.setMeasurements(15.9f, 63.2f, 1005f);
            WD.setMeasurements(15.9f, 63.4f, 1005f);
            WD.setMeasurements(15.9f, 62.9f, 1005f);
            WD.setMeasurements(15.9f, 62.8f, 1005f);
            WD.setMeasurements(15.8f, 62.9f, 1006f);
            WD.setMeasurements(15.8f, 62.9f, 1005f);
            WD.setMeasurements(15.7f, 62.8f, 1005f);
            WD.setMeasurements(15.7f, 63.0f, 1006f);
            WD.setMeasurements(15.6f, 63.2f, 1005f);
            WD.setMeasurements(15.5f, 63.1f, 1005f);
            WD.setMeasurements(15.4f, 63.2f, 1005f);

            Console.ReadKey();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var weatherData    = new WeatherData();
            var currentDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(82, 70, 29.2f);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.setMeasurements(80, 65, 30.4F);
            weatherData.setMeasurements(82, 70, 29.2F);
            weatherData.setMeasurements(78, 90, 29.2F);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            var weatherData = new WeatherData();

            var currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);

            // implement e.g. statisticsDisplay, forecastDisplay and pass the weatherData to them

            weatherData.setMeasurments(30, 65, 30.4f);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: lamnouar/Design-Patterns
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            Observer    currentConditionsDiaplay = new CurrentConditionsDisplay(weatherData);

            weatherData.SetMeasurements(24, 65, 30);
            weatherData.SetMeasurements(40, 1, 20);

            Console.ReadLine();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            var weatherData    = new WeatherData();
            var currentDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.setMeasurements(new WeatherDataObserverInput(80, 65, 30.4f));
            weatherData.setMeasurements(new WeatherDataObserverInput(82, 70, 29.2f));
            weatherData.setMeasurements(new WeatherDataObserverInput(78, 90, 29.2f));
            Console.ReadLine();
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Weather Station");
            WeatherData weatherData          = new WeatherData();
            CurrentConditionsDisplay display = new CurrentConditionsDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(82, 70, 29.2f);
            weatherData.SetMeasurements(78, 90, 29.2f);
        }
コード例 #9
0
        public static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.setMeasurements(80, 65, 34.5f);
            weatherData.setMeasurements(45, 78, 32.5f);
            weatherData.setMeasurements(78, 90, 37.5f);
            Console.ReadKey();
        }
コード例 #10
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentConditions = new CurrentConditionsDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(82, 70, 29.2f);
            weatherData.SetMeasurements(78, 90, 29.2f);
            Console.ReadLine();
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: fergal/ObserverDemo
 static void Main(string[] args)
 {
     WeatherData weatherData = new WeatherData();
     CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);
     ProjectedConditionsDisplay projectedDisplay = new ProjectedConditionsDisplay(weatherData);
     weatherData.SetMeasurements(80, 65, 30.4f);
     weatherData.SetMeasurements(82, 70, 29.2f);
     weatherData.SetMeasurements(68, 90, 45.6f);
     Console.Read();
 }
コード例 #12
0
        /// <summary>
        /// The Observer Pattern defines a one-to-many dependency between objects so that
        /// when one object changes state, all of its dependents are notified and updated
        /// automatically. Object which changes state is called - subject. Object which
        /// subscribes to subject is called - observer.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var weatherData    = new WeatherData();
            var currentDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.SetMeasurments(80, 65, 30.4f);
            Thread.Sleep(2000);
            weatherData.SetMeasurments(82, 10, 29.4f);
            Thread.Sleep(2000);
            weatherData.SetMeasurments(78, 90, 29.2f);
        }
コード例 #13
0
        static void Main(string[] args)
        {
            WeatherStation           weatherStation           = new WeatherStation();
            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherStation);
            StatisticsDisplay        statisticsDisplay        = new StatisticsDisplay(weatherStation);
            HeatIndexDisplay         heatIndexDisplay         = new HeatIndexDisplay(weatherStation);

            weatherStation.setMeasurements(80, 65, 30.4);
            weatherStation.setMeasurements(82, 70, 29.2);
            weatherStation.setMeasurements(78, 90, 29.2);
        }
コード例 #14
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentDisplay  = new CurrentConditionsDisplay(weatherData);
            ForecastDisplay          forecastDisplay = new ForecastDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4F);
            weatherData.SetMeasurements(82, 70, 29.2F);
            weatherData.SetMeasurements(78, 90, 29.2F);

            Console.ReadKey();
        }
コード例 #15
0
        private static void Main(string[] args)
        {
            var weatherData = new WeatherData();

            var currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);

            currentConditionsDisplay.Unsubscribe();

            weatherData.SetMeasurements(80, 65, 30.4f);
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: owenhuang91/DesignPattern
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.setMeasurement(80, 65, 30.4f);
            weatherData.setMeasurement(82, 70, 29.2f);
            currentDisplay.RemoveObserver();
            weatherData.setMeasurement(78, 90, 29.2f);

            Console.ReadLine();
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: hbrenes/pucmm
        static void Main(string[] args)
        {
            WeatherData wd = new WeatherData();

            var cc = new CurrentConditionsDisplay(wd);
            var t  = new CurrentPressure(wd);

            wd.Temperature = 30;
            wd.Pressure    = 989;

            Console.Read();
        }
コード例 #18
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.setMeasurement(80, 65, 30.4f);
            weatherData.setMeasurement(82, 70, 29.2f);
            currentDisplay.RemoveObserver();
            weatherData.setMeasurement(78, 90, 29.2f);

            Console.ReadLine();
        }
コード例 #19
0
        static void Main(string[] args)
        {
            var weatherData = new WeatherData();

            var currentConditions  = new CurrentConditionsDisplay(weatherData);
            var averageTemperature = new AverageTemperatureDisplay(weatherData);

            weatherData.SetMeasurements(72, 30, 25);
            weatherData.SetMeasurements(75, 32, 30);
            weatherData.SetMeasurements(80, 25, 20);

            Console.ReadLine();
        }
コード例 #20
0
        static void Main(string[] args)
        {
            WeatherData wd = new WeatherData();
            CurrentConditionsDisplay cd = new CurrentConditionsDisplay(wd);

            wd.SetMeasurements(80, 65, 30.4f);
            wd.SetMeasurements(82, 70, 29.2f);
            wd.SetMeasurements(78, 90, 29.2f);

            while (true)
            {
            }
        }
コード例 #21
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.RegisterObserver(currentDisplay);

            weatherData.SetMeasurements(80, 65, 30.4);
            weatherData.SetMeasurements(82, 70, 29.2);
            weatherData.SetMeasurements(78, 90, 29.2);

            Console.ReadKey();
        }
コード例 #22
0
        static void Main(string[] args)
        {
            var weatherData = new WeatherData();

            var forecastDisplay          = new ForecastDisplay(weatherData);
            var statisticsDisplay        = new StatisticsDisplay(weatherData);
            var thirdPartyDisplay        = new ThirdPartyDisplay(weatherData);
            var currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.SetMeasurements(80.0f, 100.0f, 1100.012f);
            weatherData.SetMeasurements(90.0f, 130.0f, 1500.012f);
            weatherData.SetMeasurements(910.0f, 120.0f, 1700.012f);
        }
コード例 #23
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay current    = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statistics = new StatisticsDisplay(weatherData);

            weatherData.SetMeasurements(80f, 65f, 30.4f);
            weatherData.SetMeasurements(90f, 70f, 34.4f);
            weatherData.SetMeasurements(85f, 60f, 29.4f);

            Console.ReadKey();
        }
コード例 #24
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentConditions = new CurrentConditionsDisplay(weatherData);
            HeatIndex heatIndex = new HeatIndex(weatherData);

            weatherData.SetMeasurements(12, 43, 76);
            weatherData.SetMeasurements(43, 32, 63);
            weatherData.SetMeasurements(32, 43, 53);

            Console.ReadKey();
        }
コード例 #25
0
        private static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);

            //StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData);
            //ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(80, 70, 29.3f);
            weatherData.SetMeasurements(78, 90, 29.2f);

            Console.ReadKey();
        }
コード例 #26
0
ファイル: Program.cs プロジェクト: AnatolyShk/C_Sharp
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentDisplay  = new CurrentConditionsDisplay(weatherData);
            CurrentHumidityDisplay   currentDisplay2 = new CurrentHumidityDisplay(weatherData);
            CurrentPressureDisplay   currentDisplay3 = new CurrentPressureDisplay(weatherData);

            weatherData.setMeasurements(20, 60, 30);
            weatherData.setMeasurements(23, 55, 20);
            weatherData.setMeasurements(25, 50, 25);
            weatherData.setMeasurements(22, 52, 30);
            weatherData.setMeasurements(20, 70, 40);
            Console.ReadLine();
        }
コード例 #27
0
        static void Main(string[] args)
        {
            //first create the weatherdata object
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay cd = new CurrentConditionsDisplay(weatherData);

            //StatisticsDisplay
            //ForecastDisplay

            //simulate new weather measurements
            weatherData.setMeasurements(60, 65, 40);
            weatherData.setMeasurements(70, 45, 30);
            weatherData.setMeasurements(80, 65, 48);
        }
コード例 #28
0
        static void Main(string[] args)
        {
            //register the subject (What everyone is listening to)
            WeatherData weatherData = new WeatherData();

            //register the observer passing the subject (who is actually listening)
            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);
            ChangedConditionsDisplay changedConditionsDisplay = new ChangedConditionsDisplay(weatherData);

            //update the subject (this will send the data to all the subjects)
            weatherData.setMeasurements(80, 65, 30);
            weatherData.setMeasurements(20, 20, 20);

            Console.ReadKey();
        }
コード例 #29
0
        static void Main(string[] args)
        {
            Console.WriteLine("Whether Data Start");

            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentDisplay       = new CurrentConditionsDisplay(weatherData);
            AwfulForecastDisplay     awfulForecastDisplay = new AwfulForecastDisplay(weatherData);

            weatherData.SetMeaturements(27, 65, 30.4f);
            weatherData.SetMeaturements(28, 5, 29.2f);
            weatherData.SetMeaturements(26, 20, 29.2f);

            Console.ReadLine();
        }
コード例 #30
0
ファイル: Program.cs プロジェクト: rdhariwal/design-patterns
        private static void ObserverDesignPattern()
        {
            Console.WriteLine("Observer Pattern Example:");
            Console.WriteLine("-------------------------------------------------------------------");
            var weatherStation = new WeatherStation();

            var currentConditionsDisplay = new CurrentConditionsDisplay();
            var staticsDisplay = new StaticsDisplay();

            weatherStation.registerObserver(currentConditionsDisplay);
            weatherStation.registerObserver(staticsDisplay);

            weatherStation.setMeasurements(12, 23, 45);

            Console.WriteLine("-------------------------------------------------------------------");
        }
コード例 #31
0
        static void Main(string[] args)
        {
            // create subject weather data to get updated from the weather station
            WeatherData weatherData = new WeatherData();

            // create three differenet display observers
            CurrentConditionsDisplay currentDisplay    = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay   = new ForecastDisplay(weatherData);
            HeadIndexDisplay         heatIndexDisplay  = new HeadIndexDisplay(weatherData);

            // simulate new weather measurements
            weatherData.setMeasurements(80, 65, 30.4f);
            weatherData.setMeasurements(82, 70, 29.2f);
            weatherData.setMeasurements(78, 90, 29.2f);
        }
コード例 #32
0
        /// <summary>
        ///     Esta tecnica, hace uso de las interfaces proveidas por el framework
        ///     <see cref="IObservable{T}" /> <see cref="IObserver{T}" />
        /// </summary>
        private static void TechniqueUsingNet()
        {
            var provider     = new WeatherDataProvider();              //creamos el proveedor
            var currentDisp  = new CurrentConditionsDisplay(provider); //Suscribimos a [Condiciones actuales] al proveedor
            var forecastDisp = new ForecastDisplay(provider);          //Suscribimos a [Prediciones del clima] al proveedor

            provider.SetMeasurements(40, 78, 3);                       //Indicamos al proveedor unas condiciones de clima
            Console.WriteLine();
            provider.SetMeasurements(45, 79, 4);                       //..
            Console.WriteLine();
            provider.SetMeasurements(46, 73, 6);                       //..
            //Remove forecast display
            forecastDisp.Unsubscribe();                                // Desinscribimos a [Prediciones del clima] debido a que éste ya no desea ser notificado
            Console.WriteLine();
            provider.SetMeasurements(36, 53, 8);                       //Comprobamos que al indicar unas nuevas condiciones de clima, el observador [Prediciones del clima] ya no es notificado
            Console.Read();
        }
コード例 #33
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();
        }
コード例 #34
0
        static void Main(string[] args)
        {
            /*
             * The Observer Pattern: defines a one-to-many
             * dependency between objects so that when one
             * object changes state, all of its dependents are
             * notified and updated automatically.
             *
             * Design principle: Strive for loosely coupled designs between objects that interact.
             *
             */

            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(82, 70, 29.2f);
            weatherData.SetMeasurements(78, 90, 29.2f);

            Console.ReadKey();
        }