示例#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();
            var observerB = new ConcreteObserverB();

            subject.Attach(observerA);
            subject.Attach(observerB);

            subject.SomeBusinessLogic();
        }
示例#3
0
        static void Main(string[] args)
        {
            var publisher = new Publisher();

            var observerA = new ConcreteObserverA();
            var observerB = new ConcreteObserverB();

            publisher.AddObserver(observerA);
            publisher.AddObserver(observerB);

            publisher.SomeBusinessLogic();
            publisher.SomeBusinessLogic();

            publisher.RemoveObserver(observerA);
            publisher.RemoveObserver(observerB);

            publisher.SomeBusinessLogic();
        }
        static void Main(string[] args)
        {
            //创建主题对象
            ConcreteSubject Bucciarati = new ConcreteSubject();

            //创建订阅者
            ConcreteObserverA Prosciutto = new ConcreteObserverA("普罗修特");
            ConcreteObserverB Pesci      = new ConcreteObserverB("贝西");

            //订阅者订阅主题对象(委托的多播)
            Bucciarati.Update += new EventHandler(Prosciutto.Attack);
            Bucciarati.Update += new EventHandler(Pesci.Shout);

            //主题对象通知事件
            Bucciarati.Notify();

            Console.Read();
        }
示例#5
0
        public void Main()
        {
            // 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();
        }