コード例 #1
0
        public static void Main(string[] args)
        {
            ConcreteObserver  observer1         = new ConcreteObserver();
            ConcreteObserver  observer2         = new ConcreteObserver();
            ConcretePublisher concretePublisher = new ConcretePublisher("teste");

            concretePublisher.AttachObserver(observer1);
            concretePublisher.AttachObserver(observer2);
            concretePublisher.ChangeValue("test2");
        }
コード例 #2
0
        private static void Main(string[] args)
        {
            // Configure Observer pattern

            ConcretePublisher s = new ConcretePublisher();

            s.Attach(new ConcreteSubscriber(s, "X"));
            s.Attach(new ConcreteSubscriber(s, "Y"));
            s.Attach(new ConcreteSubscriber(s, "Z"));

            // Change subject and notify observers

            s.SubjectState = "ABC";
            s.Notify();

            // Wait for user

            Console.ReadKey();
        }
コード例 #3
0
        // Constructor

        public ConcreteSubscriber(
            ConcretePublisher subject, string name)
        {
            this._subject = subject;
            this._name    = name;
        }