Пример #1
0
        // Use this for initialization
        void Start()
        {
            //WeatherStation sw = new WeatherStation();
            //BillboardA a = new BillboardA();
            //BillboardB b = new BillboardB();
            //BillboardC c = new BillboardC();
            //sw.Update(a,b,c);
            ConcreteSubject1  sub1 = new ConcreteSubject1();
            ConcreteObserver1 ob1  = new ConcreteObserver1(sub1);

            sub1.RegisterObserver(ob1);

            ConcreteObserver2 ob2 = new ConcreteObserver2(sub1);

            sub1.RegisterObserver(ob2);

            sub1.SubjectState = "温度 90";
        }
        static void Main(string[] args)
        {
            var subject   = new ConcreteSubject();
            var observer1 = new ConcreteObserver1();

            subject.Attach(observer1);

            var observer2 = new ConcreteObserver2();

            subject.Attach(observer2);

            var observer3 = new ConcreteObserver3();

            subject.Attach(observer3);


            subject.BusinessLogic();
            subject.BusinessLogic();

            subject.Detach(observer3);

            subject.BusinessLogic();
        }