static void Main(string[] args) { Console.WriteLine("欢迎大家来到软谋教育.net高级班公开课之设计模式特训课,今天是Eleven老师为大家带来的中介者模式"); SomebodyA somebodyA = new SomebodyA("梦"); SomebodyB somebodyB = new SomebodyB("谁"); somebodyA.SendMessage("解决消息不对称", somebodyB); Console.WriteLine("*******************************"); somebodyB.SendMessage("沟通两个不同的对象,搭建一个第三方平台,实现解耦", somebodyA); Console.WriteLine("*******************************"); Student studentA = new Student("为什么"); Student studentB = new Student("think&clever"); Student studentC = new Student("帘外月朦明"); Student studentD = new Student("采菊花的小百合"); Student studentE = new Student("风之MX"); Student studentF = new Student(" 番茄沙司 Melissa(163-番茄-上海)"); Student studentG = new Student(" 晴月"); Student studentH = new Student(" 香蕉树上两苹果"); ChatMediator mediator1 = new ChatMediator(new List <Student>() { studentA, studentB }); studentA.SendMessage("我今天很开心", mediator1); studentB.SendMessage("我今天也很开心", mediator1); studentA.SendMessage("这是为什么呢", mediator1); studentB.SendMessage("因为我学到了中介者模式,你是为什么呢", mediator1); studentA.SendMessage("我是因为上榜了", mediator1); studentB.SendMessage("我也上榜了", mediator1); ChatMediator mediator2 = new ChatMediator(new List <Student>() { studentA, studentC }); studentA.SendMessage("我今天很开心", mediator2); studentC.SendMessage("我今天也很开心", mediator2); Console.WriteLine("**************群聊**************"); ChatMediator mediator3 = new ChatMediator(new List <Student>() { studentA, studentB, studentC, studentD, studentE, studentF, studentG, studentH }); studentF.SendMessage("欢迎大家加入高级班", mediator3); Console.Read(); }
static void Main(string[] args) { { ChatMediator chat = new ChatMediator(); IUser user1 = new PremiumUser() { Name = "FirstPerson" }; IUser user2 = new BasicUser() { Name = "SecondPerson" }; IUser user3 = new BasicUser() { Name = "ThirdsPerson" }; chat.AddUser(user1); chat.AddUser(user2); chat.AddUser(user3); chat.SendMessage(user1, "Welcome"); Console.ReadLine(); } }
static void Main(string[] args) { ChatMediator chat = new ChatMediator(); IUser user1 = new PremiumUser() { Name = "AJ" }; IUser user2 = new BasicUser() { Name = "Asuma" }; IUser user3 = new BasicUser() { Name = "Kurenai" }; chat.AddUser(user1); chat.AddUser(user2); chat.AddUser(user3); chat.SendMessage(user1, "Haiiii"); chat.SendMessage(user3, "Helllo"); Console.ReadLine(); Console.ReadLine(); }
static void Main(string[] args) { ChatMediator chatMediator = new ChatMediator(); IUser u1 = new BasicUser(); u1.Name = "Arthur"; IUser u2 = new PremiumUser(); u2.Name = "Bruce"; IUser u3 = new BasicUser(); u3.Name = "Clark"; chatMediator.AddUser(u1); chatMediator.AddUser(u2); chatMediator.AddUser(u3); chatMediator.SendMessage(u1, "Hello"); //Console.WriteLine("\n\n***********\n\n"); //chatMediator.SendMessage(u2, "hii guys"); Console.ReadLine(); }
static void Main(string[] args) { IChatMediator mediator = new ChatMediator(); User user1 = new User(mediator, "A"); User user2 = new User(mediator, "B"); User user3 = new User(mediator, "C"); User user4 = new User(mediator, "D"); user1.Send("Hello"); }
static void Main(string[] args) { IChatMediator chatMediator = new ChatMediator(); IUser john = new BasicUser(chatMediator, "John"); IUser tina = new PremiumUser(chatMediator, "Tina"); IUser lara = new PremiumUser(chatMediator, "Lara"); chatMediator.Register(john); chatMediator.Register(tina); chatMediator.Register(lara); tina.SendMessage("Hello Everyone!"); Console.ReadLine(); }
public void WhenUserLoginsChatSaysHelloToAll() { var chatMediator = new ChatMediator(); var chatUser = new ChatUser("Alex", chatMediator); chatUser.RegisterUser(); Assert.That(chatUser.LastMessage, Is.Empty); var chatUser2 = new ChatUser("Joe", chatMediator); chatUser2.RegisterUser(); Assert.That(chatUser2.LastMessage, Is.Empty); Assert.That(chatUser.LastMessage, Is.Not.Empty); }
public static void Main(string[] args) { IChatMediator chatMediator = new ChatMediator(); User me = new UserOne("Forhad", chatMediator); User person1 = new UserOne("Shuvo", chatMediator); User person2 = new UserOne("Sujon", chatMediator); User person3 = new UserOne("Moin", chatMediator); chatMediator.AddPerson(person1); chatMediator.AddPerson(person2); chatMediator.AddPerson(person3); me.Send("Hi All, How are you?"); Console.ReadLine(); }
static void Main(string[] args) { ChatMediator ChatMed = new ChatMediator(); IUser Sam = new BasicUser(ChatMed, "Sam"); IUser Ram = new BasicUser(ChatMed, "Ram"); IUser Tam = new BasicUser(ChatMed, "Tam"); IUser Pam = new PremiumUser(ChatMed, "Pam"); ChatMed.AddUser(Sam); ChatMed.AddUser(Ram); ChatMed.AddUser(Tam); ChatMed.AddUser(Pam); Console.WriteLine(); Sam.SendMessage("Hello All !!!"); Console.WriteLine(); Console.Read(); }
private static void Main(string[] args) { Console.WriteLine("Mediator Pattern"); IChatMediator chatMediator = new ChatMediator(); // Didn't use var to explicity show the types. ICharacter bart = new YoungCharacter(chatMediator, "Bart"); ICharacter grandpa = new OldCharacter(chatMediator, "Grandpa Abraham Simpson"); ICharacter lisa = new YoungCharacter(chatMediator, "Lisa"); chatMediator.AddCharacter(bart); chatMediator.AddCharacter(grandpa); chatMediator.AddCharacter(lisa); bart.SendMessage("Grandpa, why don't you tell a story?"); lisa.SendMessage("Yeah Grandpa, you lived a long and interesting life."); grandpa.SendMessage("That's a lie and you know it."); Console.ReadLine(); }
static void Main(string[] args) { ChatMediator chatMediator = new ChatMediator(); IUser u1 = new BasicUser(); u1.Name = "Anirudh"; IUser u2 = new PremiumUser(); u2.Name = "Yuvan"; IUser u3 = new BasicUser(); u3.Name = "Rahman"; chatMediator.AddUser(u1); chatMediator.AddUser(u2); chatMediator.AddUser(u3); chatMediator.SendMessage(u1, "Hello Everyone"); Console.ReadLine(); }
public void SendMessage(string text, ChatMediator mediator)//中介应该有个接口 { Console.WriteLine("{0} Send: {1}", this.Name, text); mediator.SendMessage(this, text); }