Esempio n. 1
0
        private void ValueHasChanged(Object sender, EventArgs e)
        {
            Speedometer speedo = (Speedometer)sender;

            if (speedo.CurrentSpeed > SPEED_TO_ALERT)
            {
                Console.WriteLine("** ALERT ** Driving too fast! ("
                                  + speedo.CurrentSpeed + ")");
            }
            else
            {
                Console.WriteLine("... nice and steady ... ("
                                  + speedo.CurrentSpeed + ")");
            }
        }
Esempio n. 2
0
        static void Main()
        {
            // Create a speedometer...
            Speedometer speedo = new Speedometer();

            // Create a monitor...
            SpeedMonitor monitor = new SpeedMonitor(speedo);

            // Add automatic gearbox as an observer
            AutomaticGearbox auto = new AutomaticGearbox(speedo);

            // Drive at different speeds...
            speedo.CurrentSpeed = 50;
            speedo.CurrentSpeed = 70;
            speedo.CurrentSpeed = 40;
            speedo.CurrentSpeed = 100;
            speedo.CurrentSpeed = 69;

            Console.Read();
        }
Esempio n. 3
0
        static void Main()
        {
            // Create a speedometer...
            Speedometer speedo = new Speedometer();

            // Create a monitor...
            SpeedMonitor monitor = new SpeedMonitor(speedo);

            // Add automatic gearbox as an observer
            AutomaticGearbox auto = new AutomaticGearbox(speedo);

            // Drive at different speeds...
            speedo.CurrentSpeed = 50;
            speedo.CurrentSpeed = 70;
            speedo.CurrentSpeed = 40;
            speedo.CurrentSpeed = 100;
            speedo.CurrentSpeed = 69;

            Console.Read();
        }
Esempio n. 4
0
        private void ValueHasChanged(Object sender, EventArgs e)
        {
            Speedometer speedo = (Speedometer)sender;

            if (speedo.CurrentSpeed <= 10)
            {
                Console.WriteLine("Now in first gear");
            }
            else if (speedo.CurrentSpeed <= 20)
            {
                Console.WriteLine("Now in second gear");
            }
            else if (speedo.CurrentSpeed <= 30)
            {
                Console.WriteLine("Now in third gear");
            }
            else
            {
                Console.WriteLine("Now in fourth gear");
            }
        }
Esempio n. 5
0
 public AutomaticGearbox(Speedometer speedo)
 {
     speedo.ValueChanged += ValueHasChanged;
 }
Esempio n. 6
0
 public SpeedMonitor(Speedometer speedo)
 {
     speedo.ValueChanged += ValueHasChanged;
 }
Esempio n. 7
0
 public SpeedMonitor(Speedometer speedo)
 {
     speedo.ValueChanged += ValueHasChanged;
 }
Esempio n. 8
0
 public AutomaticGearbox(Speedometer speedo)
 {
     speedo.ValueChanged += ValueHasChanged;
 }