コード例 #1
0
   public ConcreteObserver(
 ConcreteSubject subject, string name)
   {
       this._subject = subject;
         this._name = name;
   }
コード例 #2
0
        private void btnObsever_Click(object sender, EventArgs e)
        {
            ConcreteSubject s = new ConcreteSubject();
            s.Attach(new ConcreteObserver(s, "X"));
            s.Attach(new ConcreteObserver(s, "Y"));
            s.Attach(new ConcreteObserver(s, "Z"));
            s.SubjectState = "ABC";
            s.Notify();

            //IBM ibm = new IBM("IBM", 120.00);
            //ibm.Attach(new Investor("Sorros"));
            //ibm.Attach(new Investor("Berkshire"));

            //// Fluctuating prices will notify investors
            //ibm.Price = 120.10;
            //ibm.Price = 121.00;

            // Wait for user
        }