Пример #1
0
 public Observer(Subject subject, string name, string gap)
 {
     this.subject = subject;
     this.name = name;
     this.gap = gap;
     subject.Notify += Update;
 }
Пример #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();
 }
Пример #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();
 }
Пример #4
0
 public override void Update(Subject s)
 {
     Console.WriteLine("{0} observed that {1} changed", GetType().Name, s.GetType().Name);
 }
Пример #5
0
 public abstract void Update(Subject s);
Пример #6
0
 public CurrentConditionsDisplay(Subject weatherData)
 {
     this.weatherData = weatherData;
     weatherData.RegisterObserver(this);
 }
Пример #7
0
 public ThirdPartyDisplay(Subject weatherData)
 {
     this.WeatherData = weatherData;
     this.WeatherData.RegisterObserver(this);
 }
Пример #8
0
 public HeatIndexDisplay(Subject s)
 {
     weatherData = s;
     weatherData.RegisterObserver(this);
 }
Пример #9
0
 public CurrentConditionsDisplay(Subject s)
 {
     weatherData = s;
     weatherData.RegisterObserver(this);
 }
Пример #10
0
 public StatisticsDisplay(Subject s)
 {
     weatherData = s;
     weatherData.RegisterObserver(this);
 }
Пример #11
0
 public ForecastDisplay(Subject weatherData)
 {
     this.WeatherData = weatherData;
     WeatherData.RegisterObserver(this);
 }
Пример #12
0
 public StatisticsDisplay(Subject weatherData)
 {
     this.WeatherData = weatherData;
     this.WeatherData.RegisterObserver(this);
 }