Example #1
0
        static void Main(string[] args)
        {
            var subject   = new Subject();
            var observerA = new ConcreteObserverA();

            subject.Attach(observerA);

            var observerB = new ConcreteObserverB();

            subject.Attach(observerB);

            subject.SomeBusinessLogic();
            subject.SomeBusinessLogic();
            subject.Dettach(observerB);
            subject.SomeBusinessLogic();
        }
Example #2
0
        static void Main(string[] args)
        {
            var subject          = new Subject();
            var concreateObjectA = new ConcreteObserver();

            subject.Add(concreateObjectA);

            subject.SomeBusinessLogic();

            Console.ReadLine();
        }
Example #3
0
        static void Main(string[] args)
        {
            var rnd       = new Random();
            var subject   = new Subject();
            var observerA = new ConcreteObserverA();
            int delay;

            lock (rnd);
            delay = rnd.Next(1, 1001);
            Thread.Sleep(delay);
            subject.Attach(observerA);

            var observerB = new ConcreteObserverB();

            subject.Attach(observerB);

            subject.SomeBusinessLogic();
            subject.SomeBusinessLogic();

            subject.Detach(observerB);

            subject.SomeBusinessLogic();
        }