Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Collections;
- namespace HeadFirstDesignPatterns.Ch02TheObserverPattern.WeatherStation
- {
- class WeatherData : Subject
- {
- private ArrayList observers;
- private float temperature;
- private float humidity;
- private float pressure;
- public WeatherData()
- {
- observers = new ArrayList();
- }
- public void RegisterObserver(Observer o)
- {
- observers.Add(o);
- }
- public void RemoveObserver(Observer o)
- {
- int i = observers.IndexOf(o);
- if (i > 0)
- {
- observers.Remove(i);
- }
- }
- public void NotifyObservers()
- {
- for (int i = 0; i < observers.Count; i++)
- {
- Observer observer = (Observer)observers[i];
- observer.update(temperature, humidity, pressure);
- }
- }
- public void measurementsChanged()
- {
- NotifyObservers();
- }
- public void setMeasurements(float temperature, float humidity, float pressure)
- {
- this.temperature = temperature;
- this.humidity = humidity;
- this.pressure = pressure;
- measurementsChanged();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement