Exemple #1
0
 public Observer(Subject subject, string name, string gap)
 {
     this.subject = subject;
     this.name = name;
     this.gap = gap;
     subject.Notify += Update;
 }
Exemple #2
0
 static void Main(string[] args)
 {
     Subject subject = new Subject();
     Observer Observer = new Observer(subject, "Center", "\t\t");
     Observer observer2 = new Observer(subject, "Right", "\t\t\t\t");
     subject.Go();
     Console.Read();
 }
Exemple #3
0
 static void Main(string[] args)
 {
     Subject subject = new Subject(5);
     // Observer1 takes a subscription to the store
     var observer1 = new Observar("Observer 1");
     subject.Subscribe(observer1);
     // Observer2 also subscribes to the store
     subject.Subscribe(new Observar("Observer 2"));
     subject.Data++;
     // Observer1 unsubscribes and Observer3 subscribes to notifications.
     subject.Unsubscribe(observer1);
     subject.Subscribe(new Observar("Observer 3"));
     subject.Data++;
     Console.ReadLine();
 }
 public override void Update(Subject s)
 {
     Console.WriteLine("{0} observed that {1} changed", GetType().Name, s.GetType().Name);
 }
 public abstract void Update(Subject s);
Exemple #6
0
 public CurrentConditionsDisplay(Subject weatherData)
 {
     this.weatherData = weatherData;
     weatherData.RegisterObserver(this);
 }
 public ThirdPartyDisplay(Subject weatherData)
 {
     this.WeatherData = weatherData;
     this.WeatherData.RegisterObserver(this);
 }
 public HeatIndexDisplay(Subject s)
 {
     weatherData = s;
     weatherData.RegisterObserver(this);
 }
 public CurrentConditionsDisplay(Subject s)
 {
     weatherData = s;
     weatherData.RegisterObserver(this);
 }
 public StatisticsDisplay(Subject s)
 {
     weatherData = s;
     weatherData.RegisterObserver(this);
 }
 public ForecastDisplay(Subject weatherData)
 {
     this.WeatherData = weatherData;
     WeatherData.RegisterObserver(this);
 }
 public StatisticsDisplay(Subject weatherData)
 {
     this.WeatherData = weatherData;
     this.WeatherData.RegisterObserver(this);
 }