structure
Code
Using system; using system.collections;
A summary description of Namespace ExempleObserver {///
// "ConcreteSubject" class ConcreteSubject: Subject {// Fields private ArrayList observers = new ArrayList (); // Methods public void Attach (Observer observer) {observers.Add (observer);} public void Detach (Observer observer) {observers .Remove (observer);} public void Notify () {foreach (Observer o in observers) o.Update ();} // Fields private string subjectState; // Properties public string subjectState {get {return subjectState;} set {subjectState = value;}}} // "Observer" interface Observer {// Methods void Update ();} // "ConcreteObserver" class ConcreteObserver: Observer {// Fields private string name; private string observerState; private ConcreteSubject subject; // Constructors public ConcreteObserver (ConcreteSubject subject, string name) {this.subject = subject; this.name = name;} // Methods public void Update () {observerState = subject.SubjectState; Console.WriteLine ( "Observer {0} 's New stat e is {1} ", name, observerstate);} // Properties Public ConcreteSubject Subject;} set {subject = value;}}}} ///