Esempio n. 1
0
    private void Start()
    {
        ConcreteObserver1 observer1 = new ConcreteObserver1(subject1);

        subject1.RegisterObserver(observer1);

        //subject1.SubjectState = "猫进来了";  //主题的数据被赋值时,就去更新了观察者的状态 ----这句代码可以放到一个点击事件里
    }
Esempio n. 2
0
    private void Start()
    {
        ConcreteSubject1  sub1 = new ConcreteSubject1();
        ConcreteObserver1 ob1  = new ConcreteObserver1(sub1);

        sub1.RegisterObserver(ob1);

        sub1.SubjectState = "更新了一条消息";
    }
Esempio n. 3
0
    private void Start()
    {
        //WeatherStation ws = new WeatherStation();

        //BillboardA a = new BillboardA();
        //BillboardB b = new BillboardB();
        //BillboardC c = new BillboardC();

        //ws.Update(a, b, c);

        ConcreteSubject1 sub1 = new ConcreteSubject1();

        ConcreteObserver1 ob1 = new ConcreteObserver1(sub1);
        ConcreteObserver2 ob2 = new ConcreteObserver2(sub1);

        sub1.RegisterObserver(ob1);
        sub1.RegisterObserver(ob2);

        sub1.subjectState = "温度";
    }
Esempio n. 4
0
    private void Start()
    {
        //WeatherStation weather = new global::WeatherStation();

        //BillBoardA a = new BillBoardA();
        //BillBoardB b = new BillBoardB();
        //BillBoardC c = new BillBoardC();

        //weather.Update(a,b,c);

        ////不符合开闭原则 :对修改关闭,对扩展开放
        ////当需求变更,我们需要扩展显示布告板D,E,F....我们就得必须修改 WeatherStation的Update()


        ConcreteSubject1 sub1 = new ConcreteSubject1();

        sub1.RegisterObserver(new  ConcreteObserver1(sub1));
        sub1.RegisterObserver(new  ConcreteObserver2(sub1));

        sub1.subjectState = "温度 27,湿度 18,气候 多云";
        sub1.subjectState = "温度 32,湿度 24,气候 晴天";
    }
Esempio n. 5
0
    void Start()
    {
        //WeatherStation mWeatherStation = new WeatherStation();

        //BillboardA mBillboardA = new BillboardA();
        //BillboardB mBillboardB = new BillboardB();
        //BillboardC mBillboardC = new BillboardC();

        //mWeatherStation.mBillboardHandler += mBillboardA.Show;
        //mWeatherStation.mBillboardHandler += mBillboardB.Show;
        //mWeatherStation.mBillboardHandler += mBillboardC.Show;

        //mWeatherStation.Update();

        ConcreteSubject1  mConcreteSubject1  = new ConcreteSubject1();
        ConcreteObserver1 mConcreteObserver1 = new ConcreteObserver1(mConcreteSubject1);

        mConcreteSubject1.RegisterObserver(mConcreteObserver1);


        mConcreteSubject1.subjectState = "状态改变";
    }