public static void Main(string[] args) { ConcreteObserver observer1 = new ConcreteObserver(); ConcreteObserver observer2 = new ConcreteObserver(); ConcretePublisher concretePublisher = new ConcretePublisher("teste"); concretePublisher.AttachObserver(observer1); concretePublisher.AttachObserver(observer2); concretePublisher.ChangeValue("test2"); }
private static void Main(string[] args) { // Configure Observer pattern ConcretePublisher s = new ConcretePublisher(); s.Attach(new ConcreteSubscriber(s, "X")); s.Attach(new ConcreteSubscriber(s, "Y")); s.Attach(new ConcreteSubscriber(s, "Z")); // Change subject and notify observers s.SubjectState = "ABC"; s.Notify(); // Wait for user Console.ReadKey(); }
// Constructor public ConcreteSubscriber( ConcretePublisher subject, string name) { this._subject = subject; this._name = name; }