static void Main(string[] args) { ConcreteSubject1 sub1 = new ConcreteSubject1(); ConcreteObserver1 ob1 = new ConcreteObserver1(sub1); ConcreteObserver2 ob2 = new ConcreteObserver2(sub1); //观察者要执行的方法委托给发布者的更新方法上 sub1.Update += new EventHandler(ob1.MyUpdate); sub1.Update += new EventHandler(ob2.Update); sub1.SubjectState = "温度 90"; //sub1.Notify(); Console.ReadLine(); }
public ConcreteObserver2(ConcreteSubject1 sub) { mSub = sub; }