Ejemplo n.º 1
0
        public static void Main()
        {
            // Create a new clock - the publisher, which will publish the SecondChangeEvent
            Clock theClock = new Clock();

            // Create the display and tell it to
            // subscribe to the clock just created
            DisplayTimeOfClock dc = new DisplayTimeOfClock();
            dc.Subscribe(theClock);

            // Create a Log object and tell it
            // to subscribe to the clock
            LogTimeOfClock lc = new LogTimeOfClock();
            lc.Subscribe(theClock);

            //Write separator for clearer console
            Console.WriteLine("=====");

            // Get the clock started, let it run for 10 secs
            theClock.Run(1);

            //Stop DisplayTimeOfClock from observer the Clock
            dc.Unsubscribe(theClock);

            //Write separator for clearer console
            Console.WriteLine("=====");

            //Let the clock run for another 5 secs
            theClock.Run(1);
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            // Create a new clock - the publisher, which will publish the SecondChangeEvent
            Clock theClock = new Clock();

            // Create the display and tell it to
            // subscribe to the clock just created
            DisplayTimeOfClock dc = new DisplayTimeOfClock();

            dc.Subscribe(theClock);

            // Create a Log object and tell it
            // to subscribe to the clock
            LogTimeOfClock lc = new LogTimeOfClock();

            lc.Subscribe(theClock);

            //Write separator for clearer console
            Console.WriteLine("=====");

            // Get the clock started, let it run for 10 secs
            theClock.Run(1);

            //Stop DisplayTimeOfClock from observer the Clock
            dc.Unsubscribe(theClock);

            //Write separator for clearer console
            Console.WriteLine("=====");

            //Let the clock run for another 5 secs
            theClock.Run(1);
        }