Beispiel #1
0
        /*
         * Defines one-to-many dependencies between objects so that the state one changes, all dependent objects are notified.
         * Contains two main actors, Subject which notifies change and Observer that receives and acts on updates
         * Loose coupling is a benefit. However, Subject may send updates that don't matter to Observer.
         */
        static void Main(string[] args)
        {
            var stockGrabber = new StockGrabber();
            var observer1    = new Observer1();
            var observer2    = new Observer2();

            stockGrabber.Register(observer1);
            stockGrabber.Register(observer2);
            stockGrabber.SetPrice(100.00);

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Subject   mySubject   = new Subject();
            IObserver myObserver1 = new Observer1();
            IObserver myObserver2 = new Observer2();

            // register observers
            mySubject.Register(myObserver1);
            mySubject.Register(myObserver2);

            mySubject.Notify("message 1");
            mySubject.Notify("message 2");
        }
        static void Main(string[] args)
        {
            Subject   s1 = new Subject();
            IObserver o1 = new Observer1();
            IObserver o2 = new Observer2();

            s1.register(o1);
            s1.register(o2);
            s1.Flag = 5;
            s1.Flag = 25;
            s1.unregister(o1);
            s1.Flag = 50;


            /*List<string> lista1 = new List<string>() { "1", "2", "3", "4" };
             * List<string> lista2 = new List<string>() { "1", "2", "3", "6" };
             * List<string> except = lista1.exceptAll(lista2);
             *
             * except.ForEach(Console.WriteLine);
             */
            Console.ReadLine();
        }