Пример #1
0
        static void Main(string[] args)
        {
            // Observer Concept
            var subject   = new Subject();
            var observerA = new ConcreteObserverA();

            subject.Attach(observerA);

            var observerB = new ConcreteObserverB();

            subject.Attach(observerB);

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

            subject.Detach(observerB);

            subject.SomeBusinessLogic();

            //Exercice 1
            var estacion = new EstacionMetereologica();
            var dipositivoTemperatura = new DispositivoTiempoActual();

            estacion.Attach(dipositivoTemperatura);
            for (int i = 0; i < 10; i++)
            {
                estacion.medidasHanCambiado();
            }
        }
Пример #2
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.Detach(observerB);

            subject.SomeBusinessLogic();
            Console.ReadLine();
        }
Пример #3
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.Detach(observerB);

            subject.SomeBusinessLogic();
        }
Пример #4
0
        static void Main(string[] args)
        {
            // The client code.
            var subject   = new Subject();
            var observerA = new ConcreteObserverA();

            subject.Attach(observerA);

            var observerB = new ConcreteObserverB();

            subject.Attach(observerB);

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

            subject.Detach(observerB);

            subject.SomeBusinessLogic();
        }
        static void Main(string[] args)
        {
            var subject   = new Subject();
            var observerA = new ConcreteObserverA();
            var observerB = new ConcreteObserverB();

            subject.SomeBusinessLogic();

            subject.Subscribe(observerA);

            subject.Subscribe(observerB);

            subject.SomeBusinessLogic();

            subject.SomeBusinessLogic();

            subject.Unsubscribe(observerB);

            subject.SomeBusinessLogic();
        }