Ejemplo n.º 1
0
        static void Main()
        {
            // Configure Observer pattern 
            ConcreteSubject s = new ConcreteSubject();
            Observer obs_a = new ConcreteObserver(s,"X");
            Observer obs_b = new ConcreteObserver(s,"Y");
            Observer obs_c = new ConcreteObserver(s,"Z");
            
            s.Attach(obs_a);
            s.Attach(obs_b);
            s.Attach(obs_c);

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

            // Wait for user 
            Console.Read();
        }
Ejemplo n.º 2
0
    /// <summary>
    /// Entry point into console application.
    /// </summary>
    static void Main()
    {
      // 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();
    }
Ejemplo n.º 3
0
        static void Main()
        {
            // 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.Read();
        }
Ejemplo n.º 4
0
        static void Main()

        {
            ConcreteSubject s = new ConcreteSubject();

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

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

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

            //Cambia el estado y notifica

            s.SubjectState = "ABC";

            s.Notify();

            Console.ReadKey();
        }
Ejemplo n.º 5
0
 // Constructor
 public ConcreteObserver(
     ConcreteSubject subject, string name)
 {
     this.subject = subject;
     this.name    = name;
 }
Ejemplo n.º 6
0
 // Constructor
 public ConcreteObserver(
     ConcreteSubject subject, string name)
 {
     this._subject = subject;
     this._name = name;
 }