Esempio n. 1
0
        static void MainA()
        {
            Console.WriteLine("MainClassFour -> MainA");

            TrainSignal trainSignal = new TrainSignal();

            new Car(trainSignal);
            new Car(trainSignal);
            new Car(trainSignal);
            new Car(trainSignal);

            trainSignal.HereComesATrain();
            Console.WriteLine("***");
            trainSignal.TrainsAComing();
            Console.WriteLine("***");
            trainSignal.TrainsAComing = null;
            trainSignal.HereComesATrain();
        }
Esempio n. 2
0
 public Car(TrainSignal trainSignal)
 {
     trainSignal.TrainsAComing += StopTheCar; // Observer pattern
 }