static void Main(string[] args) { var subject = new Subject(); var observer1 = new Observer1(); var observer2 = new Observer2(); subject.Attach(observer1); subject.Attach(observer2); subject.NotifyChange("Test change state 1"); subject.Detach(observer2); subject.NotifyChange("Test change state 2"); Console.ReadLine(); }
public void UnitTest() { IDataProvider dataProvider = new DataProvider(32, 102, 30); ISubject subject = new WeatherData(dataProvider); IOberserver o1 = new Observer1(); IOberserver o2 = new Observer2(); IOberserver o3 = new Observer3(); subject.RegisterObserver(o1); subject.RegisterObserver(o2); subject.RegisterObserver(o3); dataProvider.ChangeTemperature(36); dataProvider.ChangePressure(110); dataProvider.ChangeTemperature(80); subject.RemoveObserver(o3); dataProvider.ChangeTemperature(31); }