static void Main(string[] args)
        {
            Thermostat thermostat = new Thermostat();

            Heater heater = new Heater(30);

            Cooler cooler = new Cooler(40);

            thermostat.Add_TemperatureChanged(heater.OnTemperatureChanged);
            thermostat.Add_TemperatureChanged(cooler.Update);

            thermostat.EmulateTemperatureChange();

            thermostat.Remove_TemperatureChanged(cooler.Update);

            thermostat.EmulateTemperatureChange();

            Type type = thermostat.GetType();

            foreach (var t in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                Console.WriteLine(t.Name);
            }

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Thermostat thermostat = new Thermostat();

            Heater heater = new Heater(30);

            Cooler cooler = new Cooler(40);

            thermostat.observers += heater.OnTemperatureChanged;
            thermostat.observers += cooler.Update;

            thermostat.EmulateTemperatureChange();

            thermostat.observers -= cooler.Update;

            thermostat.EmulateTemperatureChange();

            Console.ReadKey();
        }
Пример #3
0
    static void Main(string[] args)
    {
        Thermostat thermostat = new Thermostat();

        Heater heater = new Heater(30);

        Cooler cooler = new Cooler(40);

        thermostat.EmulateTemperatureChange();

        heater.OnTemperatureChanged(thermostat.CurrentTemperature);

        cooler.Update(thermostat.CurrentTemperature);

        thermostat.EmulateTemperatureChange();

        heater.OnTemperatureChanged(thermostat.CurrentTemperature);

        cooler.Update(thermostat.CurrentTemperature);
    }
        static void Main(string[] args)
        {
            Thermostat thermostat = new Thermostat();

            Heater heater = new Heater(30);

            Cooler cooler = new Cooler(40);

            thermostat.Register(heater);

            thermostat.Register(cooler);

            thermostat.EmulateTemperatureChange();

            thermostat.Unregister(cooler);

            thermostat.EmulateTemperatureChange();

            Console.ReadKey();
        }