コード例 #1
0
        public OberverPattern()
        {
            ConcreteSubject s=new ConcreteSubject();
            s.Attach(new ConcreteObserver(s, "a"));
            s.Attach(new ConcreteObserver(s, "b"));
            s.Attach(new ConcreteObserver(s, "c"));

            s.Attach(new TwoConcreteObserver(s, "stop"));

            s.SubjectState = "run";
            s.Notify();
            s.SubjectState = "stop";
            s.Notify();

            //用委托的方式
            var one = new ConcreteObserver(s, "a");
            var two = new TwoConcreteObserver(s, "b");

            var de=new DelegetSubject();
            de.Up += new DelegetSubject.EventHand(one.TestOneDelegate);
            de.Up += new DelegetSubject.EventHand(two.TestDelegate);
            de.Notify();
        }
コード例 #2
0
 public ConcreteObserver(ConcreteSubject subject,string name)
 {
     this.subject = subject;
     this.name = name;
 }
コード例 #3
0
 public TwoConcreteObserver(ConcreteSubject concreteTest, string name)
 {
     this.concreteTest = concreteTest;
     this.name = name;
 }