Beispiel #1
0
        static void testDesign2()
        {
            // Configure Observer pattern
            ConcreteSubject s = new ConcreteSubject();

            s.Attach(new ConcreteObserver(s, "X"));
            s.Attach(new ConcreteObserver(s, "Y"));
            s.Attach(new ConcreteObserver(s, "Z"));

            // Change subject and notify observers
            s.SubjectState = "ABC";
            s.Notify();

            // Wait for user
            Console.ReadKey();
        }
Beispiel #2
0
        static void testDesign2()
        {
            // Configure Observer pattern
            ConcreteSubject s = new ConcreteSubject();

            s.Attach(new ConcreteObserver(s, "X"));
            s.Attach(new ConcreteObserver(s, "Y"));
            s.Attach(new ConcreteObserver(s, "Z"));

            // Change subject and notify observers
            s.SubjectState = "ABC";
            s.Notify();

            // Wait for user
            Console.ReadKey();
        }
Beispiel #3
0
   // Constructor
   public ConcreteObserver(
 ConcreteSubject subject, string name)
   {
       this._subject = subject;
         this._name = name;
   }
Beispiel #4
0
 // Constructor
 public ConcreteObserver(
     ConcreteSubject subject, string name)
 {
     this._subject = subject;
     this._name    = name;
 }