Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var subject         = new Subject();
            var firstSubscriber = new FirstObserver();

            subject.Attach(firstSubscriber);

            var secondSubscriber = new SecondObserver();

            subject.Attach(secondSubscriber);

            subject.BusinessLogic();
            subject.BusinessLogic();

            subject.Detach(secondSubscriber);

            subject.BusinessLogic();
        }
Exemplo n.º 2
0
        private static void OneThread()
        {
            var subject       = new Subject();
            var observerFirst = new FirstObserver();

            subject.Attach(observerFirst);

            subject.Notify();

            var observerSecond = new SecondObserver();

            subject.Attach(observerSecond);
            subject.Attach(observerSecond);

            subject.Notify();

            subject.Detach(observerSecond);

            subject.Notify();
        }