Пример #1
0
        static void Main(string[] args)
        {
            var publisher = new TemperatureSensor();

            IListener janWorker    = new WorkerListener();
            IListener adamWorker   = new WorkerListener();
            IListener kamilaWorker = new WorkerListener();

            IListener piotrManager = new ManagerListener();

            IListener jerzyBoss = new BossListener();

            publisher.Subscribe(janWorker);
            publisher.Subscribe(adamWorker);
            publisher.Subscribe(kamilaWorker);
            publisher.Subscribe(piotrManager);
            publisher.Subscribe(jerzyBoss);

            int i = 10;

            while (--i > 0)
            {
                publisher.CheckTemperature();
            }

            Console.Read();
        }
Пример #2
0
        static void Main(string[] args)
        {
            TemperatureSensor   monitor  = new TemperatureSensor();
            TemperatureReporter reporter = new TemperatureReporter();

            reporter.StartReporting(monitor);
            monitor.Notify();
        }
Пример #3
0
        static void Main(string[] args)
        {
            TemperatureSensor   sensor   = new TemperatureSensor();
            TemperatureReporter reporter = new TemperatureReporter();

            reporter.StartReporting(sensor);
            sensor.GetTemperature();
        }
Пример #4
0
        static void Main(string[] args)
        {
            TemperatureSensor   sensor    = new TemperatureSensor();
            TemperatureReporter reporter  = new TemperatureReporter();
            DateTime            localDate = DateTime.Now;
            Temperature         a         = new Temperature(20, localDate);;

            sensor.GetTemperature();
        }
Пример #5
0
        static void Main(string[] args)
        {
            TemperatureSensor   monitor  = new TemperatureSensor();
            TemperatureReporter reporter = new TemperatureReporter();

            monitor.Subscribe(reporter);
            reporter.StartReporting();
            monitor.GetTemperature();
        }
Пример #6
0
        static void Main(string[] args)
        {
            var temperatureSensor = new TemperatureSensor();
            var heater            = new Heater(temperatureSensor, 50);
            var airConditioner    = new AirConditioner(temperatureSensor, 20);

            temperatureSensor.Temperature = 30;
            Console.WriteLine($"IsHeating: {heater.IsHeating}");
            Console.WriteLine($"IsCooling: {airConditioner.IsCooling}");
            temperatureSensor.Temperature = 10;
            Console.WriteLine($"IsHeating: {heater.IsHeating}");
            Console.WriteLine($"IsCooling: {airConditioner.IsCooling}");
            temperatureSensor.Temperature = 60;
            Console.WriteLine($"IsHeating: {heater.IsHeating}");
            Console.WriteLine($"IsCooling: {airConditioner.IsCooling}");
            Console.ReadKey();
        }
Пример #7
0
 public void StartReporting(TemperatureSensor provider)
 {
     this.provider = provider;
     this.first    = true;
     this.provider.Subscribe(this);
 }
Пример #8
0
 public void StartReporting(IObservable provider)
 {
     this.provider = (TemperatureSensor)provider;
     this.first    = true;
     this.provider.Subscribe(this);
 }