static void Main(string[] args)
        {
            MessageSubscriberOne s1 = new MessageSubscriberOne();

            MessageSubscriberTwo s2 = new MessageSubscriberTwo();

            MessageSubscriberThree s3 = new MessageSubscriberThree();

            MessagePublisher p = new MessagePublisher();

            //p.Attach(s1);

            //p.Attach(s2);

            //p.notifyUpdate(new Message("First Message")); //s1 and s2 will receive the update

            //p.Detach(s1);

            //p.Attach(s3);

            //p.notifyUpdate(new Message("Second Message")); //s2 and s3 will receive the update

            p.Attach(s1);
            p.Attach(s2);
            p.Attach(s3);

            p.ChangeState(2);

            Console.ReadLine();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            MessageSubscriberOne   s1 = new MessageSubscriberOne();
            MessageSubscriberTwo   s2 = new MessageSubscriberTwo();
            MessageSubscriberThree s3 = new MessageSubscriberThree();
            MessageSubscriberOne   s4 = new MessageSubscriberOne();
            MessagePublisher       p  = new MessagePublisher();

            p.attach(s1);
            p.attach(s2);
            p.notifyUpdate(new Message("Initial State"));
            p.detach(s1);
            p.attach(s3);
            p.UpdateState(1);
            p.attach(s4);
            p.UpdateState(1);
        }