예제 #1
0
        static void Main(string[] args)
        {
            SubjectClass subject = new SubjectClass();
            ObserverClass observer = new ObserverClass(subject);
            subject.Value1 = 10;
            subject.Value1 = 100;
            observer.List();
            Console.ReadLine();

        }
예제 #2
0
        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();
        }
예제 #3
0
 public void Unsubscribe(ObserverClass observer)
 {
     Observers.Remove(observer);
 }
예제 #4
0
 public void Subscribe(ObserverClass observer)
 {
     Observers.Add(observer);
 }