static void Main(string[] args) { SubjectClass subject = new SubjectClass(); ObserverClass observer = new ObserverClass(subject); subject.Value1 = 10; subject.Value1 = 100; observer.List(); Console.ReadLine(); }
static void Main(string[] args) { Subject subject = new Subject(); ObserverClass observer1 = new ObserverClass("Observer1"); subject.Subscribe(observer1); subject.Subscribe(new ObserverClass("Observer2")); subject.InventoryCount++; subject.Unsubscribe(observer1); subject.Subscribe(new ObserverClass("Observer3")); subject.InventoryCount++; Console.ReadLine(); }
public void Unsubscribe(ObserverClass observer) { Observers.Remove(observer); }
public void Subscribe(ObserverClass observer) { Observers.Add(observer); }