Пример #1
0
        static void Main(string[] args)
        {
            ChatMediator mediator = new ChatMediator();
            IUser        a        = new BasicUser("A", mediator);
            IUser        b        = new BasicUser("B", mediator);
            IUser        c        = new PremiumUser("C", mediator);
            IUser        d        = new PremiumUser("D", mediator);

            //adding to list of receiver
            mediator.AddUser(a);
            mediator.AddUser(b);
            mediator.AddUser(c);
            mediator.AddUser(d);
            //sending message
            a.SendMessage("Hi");

            Console.ReadLine();
        }
        /// <summary>
        /// Runners this instance.
        /// </summary>
        public void Runner()
        {
            ////creating object of chat mediator class using reference of inerface
            IChatMediator chatMediator = new ChatMediator();
            ////creating object of basic user class with abstract class reference
            User manjunath = new BasicUser(chatMediator, "Manjunath");
            ////creating object of Premium user class with abstract class reference
            User karan = new PremiumUser(chatMediator, "Karan");
            ////creating object of basic premium class with abstract class reference
            User parmesh = new PremiumUser(chatMediator, "Parmesh");

            ////calling add user method with the reference of interface
            chatMediator.AddUser(manjunath);
            ////calling add user method with the reference of interface
            chatMediator.AddUser(karan);
            ////calling add user method with the reference of interface
            chatMediator.AddUser(parmesh);
            ////creating object of basic user class with abstract class reference
            User salu = new BasicUser(chatMediator, "Salu");

            ////calling add user method with the reference of interface
            chatMediator.AddUser(salu);
            salu.SendMessage("salu:->Hey i am online");
        }