I. INTRODUCTION In real life, there are many intermediary model's figure, such as QQ game platform, chat rooms, QQ group and SMS platform, these are intermediary model used in real life, the following specific share with me understanding mediator pattern. Second, the introduction of the definition of intermediary mode 2.1 Mediator pattern can be seen from the example of life, whether it is QQ game or QQ group, they are acting as an intermediate platform, QQ users can log in the middle of the platform with other QQ users exchange, without these intermediate platform, if we want to chat with friends, you may Air Jordan Outlet only need to face it. Telephone, text messaging is also an intermediate platform, with the intermediate platform, each user do not rely directly with other users, only you need to rely on the middle of the platform you can, 579756 403 Purple White Nike Black Mamba 24 Kobe Sale all the operations by the middle platform to distribute. Complete understanding of mediation pattern in the life of the model, the following definitions are given formal mediation model. Mediator pattern defines an intermediary object to encapsulate a series of interactive relationship between objects. Mediator so that all objects do not explicitly refer to each other 579756 403 Purple White Nike Black Mamba 24 Kobe Sale between, so that the coupling is reduced, and can be varied independently interactions between them. 2.2 Mediator pattern structure from life examples will know, the mediator schema design two specific objects, a user class, and the other is an intermediary class, according to the principles for the programming interface, you need these types of roles abstract, So there is a mediator pattern in four types of roles, they are: abstract intermediary role, Air Max 2011 Womens Purple Grey in particular the role of mediator, abstract and concrete co-worker colleague class category. Mediator class is to play the role of coordination of the various objects, the abstract intermediary role you will need to save each object. With the above analysis, it is not difficult to understand the structure of FIG intermediary model, the specific structure is shown below: Why use intermediary model in real life, the agency's presence is indispensable, if not an intermediary who, Nike Free Run 3 Women we can not communicate with distant friends. In the field of software design, why use an intermediary model? If you do not use the intermediary model, then each object will be referenced mutual colleague, if each object to interact with multiple objects, will form a network structure as shown below. From the figure can be found, if you do not use the intermediary model, then excessive coupling between each object, so that is not conducive to class reuse is not conducive to expansion. If the introduction of the intermediary model, the relationship between objects will become the star structure, will form the structure shown below after use intermediaries mode: From the chart can be found, then use intermediaries mode, any of a class changes only affect intermediaries and the class itself, unlike the previous design, a kind of change will cause all classes of any changes in their association. This design greatly reduces the coupling of the system. Mediator pattern to achieve 2.3 introduction to define the need for intermediaries and the existing pattern, the following would play cards with real-life examples to achieve next mediator mode. In real life, two people playing cards, if someone wins will affect other state changes. If at this time do not use intermediary model to achieve, then achieve the above scenario is as follows: // abstract class players out public abstract class AbstractCardPartner {public int MoneyCount {get; set;} public AbstractCardPartner () {MoneyCount = 0; } public abstract void ChangeCount (int Count, AbstractCardPartner other);} // A class poker buddies public class ParterA: AbstractCardPartner {public override void ChangeCount (int Count, AbstractCardPartner other) {this.MoneyCount + = Count; other.MoneyCount - = Count;}} // New Nike Free Run 3 Shoes Silver 3 poker buddies Class B public class ParterB: AbstractCardPartner {public override void ChangeCount (int Count, AbstractCardPartner other) {this.MoneyCount + = Count; other.MoneyCount - = Count;}} class Program {// A , B two people playing cards static void Main (string 597806-400 Nike LeBron X EXT QS Denim-Pink Outlet [] args) {AbstractCardPartner A = new ParterA (); A.MoneyCount = 20; AbstractCardPartner B = new ParterB (); B.MoneyCount = 20; // A won the B money to reduce A.ChangeCount (5, B); Console.WriteLine (\u0026 quot; A money now is: {0} \u0026 quot ;, A.MoneyCount); // should be 25 Console.WriteLine (\u0026 quot; B now Money is: {0} \u0026 quot ;, B.MoneyCount); // 15 // B should win the money A reduction B.ChangeCount (10, A); Console.WriteLine (\u0026 quot; A money now is: {0} \u0026 quot ;, A.MoneyCount); // should be 15 Console.WriteLine (\u0026 quot; B now money is: {0} \u0026 quot ;, B.MoneyCount); // should be 25 Console.Read (); }} The above scenario is indeed the perfect solution to the above problem, and the use of abstract classes make specific cards Friends Friends A and B cards rely on abstract classes, thereby reducing the degree of coupling between classes adidas adiPure Crazyquick Collegiate Royal/White Q33301 Outlet colleagues. But this design, if which poker buddies A change, this time will affect the state's poker buddies B, if the object becomes more involved, then change this time one poker buddies will affect all other associated Friends of licensing status. A miscalculated such as poker buddies money, this time cards Friends A and B players out New Nike Free 5.0 V4 Grey Lime Trainers of money are not correct, and if more than one person playing cards, then the impact will be more objects. This time it will Consideration - Can count the money the program or task to count good people to calculate it, this time we have a game QQ joy Landlords and other card games up. So the above design, we still have to further improve the program, that is added to an intermediary object to coordinate the association between various objects, which is the application of the Mediator pattern, perfect after a specific implementation code as follows: namespace MediatorPattern {// abstract class players out public abstract class AbstractCardPartner {public int MoneyCount {get; set;} public AbstractCardPartner () {MoneyCount = 0;} public abstract void ChangeCount (int Count, AbstractMediator mediator);} // A poker buddies class public class ParterA: AbstractCardPartner {// rely intermediary objects and abstract public override void ChangeCount (int Count, AbstractMediator mediator) {mediator.AWin (Count);}} // poker buddies Class B public class ParterB: AbstractCardPartner New Nike Free 5.0 V4 Purple Yellow Shoes {// Dependence and abstract objects intermediary public override void ChangeCount (int Count, AbstractMediator mediator) {mediator.BWin (Count);}} // Nike Free Run 3 Women abstract Mediator class public abstract class AbstractMediator {protected AbstractCardPartner A; protected AbstractCardPartner B; public AbstractMediator (AbstractCardPartner a, AbstractCardPartner b) {A = a; B = b;} public abstract void AWin (int count); public abstract void BWin (int count);} // specific intermediary class public class MediatorPater: AbstractMediator {public MediatorPater (AbstractCardPartner a, AbstractCardPartner b): base (a, b) {} public override void AWin (int count) {A.MoneyCount + = count; B.MoneyCount - = count;} public override void BWin (int count) {B.MoneyCount Air Max 2011 Womens Grey Green + = count; A.MoneyCount - = count;}} class Program {static void Main (string [] args) {AbstractCardPartner A = new ParterA (); AbstractCardPartner B = new ParterB (); // initial money A.MoneyCount = 20; Mens Nike Free Run 3 Shoes Black 3 B.MoneyCount = 20; AbstractMediator mediator = new MediatorPater (A, B); // A win A.ChangeCount (5, mediator); Console.WriteLine (\u0026 quot; A money now is: {0} \u0026 quot; , A.MoneyCount); // should be 25 Console.WriteLine (\u0026 quot; B now money is: {0} \u0026 quot ;, B.MoneyCount); // 15 // Nike Air Max B should win B.ChangeCount (10, mediator); Console.WriteLine (\u0026 quot; A money now is: {0} \u0026 quot ;, A.MoneyCount); // should be 15 Console.WriteLine (\u0026 quot; B now money is: {0} \u0026 quot ;, B .MoneyCount); // should be 25 Console.Read ();}}} can be seen from the realization of the code above, then the cards Friends Friends A and B cards rely on intermediaries abstract class, so that if one of the cards Friends of the change only affects class, this change only affects the class itself and poker buddies intermediary class, so as to solve the problems in front of realization of the code, the specific results of the operation to achieve the same results as before, the results as shown below: in the realization of the above code, the abstract Mediator class holds two abstract class players out, if a newly added similar players out, then you have to change this abstract Mediator class. Observer mode can be combined to solve this problem, namely the abstract category abstract object holds intermediary players out, and then add Register and UnRegister approach to the management of the list, and then modify AWin and BWin method intermediaries in specific class, traverse the list count the money, and other cards to change their Friends. This design is still a problem - namely, when adding a new poker buddies, then solves the abstract Mediator class does not need to modify the problem, but this time still have to modify specific intermediary categories, namely add CWin method, We can use the state model to solve this problem, information about the state pattern will be shared in the next topic. Third, the application of the general scene mode mediator in the following circumstances, consider using an intermediary model: a well-defined set of objects, now communicate with each other to be complex. I want a middle class to encapsulate multiple classes of behavior, but do not want to generate too many subclasses. Fourth, the advantages and disadvantages of mediator pattern Mediator model has the following advantages: simplify the relationships between objects, the relationship between the various objects encapsulate system, individual coworkers class decoupling, so that the system becomes loose coupling. Providing system flexibility so that each colleague independent and easy to reuse objects. However, there are also Mediator pattern corresponding disadvantages: intermediary model, mediator role assumed more responsibility, so once this intermediary target there is a problem, the entire system would be a significant impact. For example, QQ game joy beans procedures calculated wrong, this will cause a significant impact. Add a new co-worker class, I had to modify the abstract and concrete classes intermediary intermediary class, then you can use the observer pattern and state model to solve this problem. V. Summary intermediary model, defines the interaction between an intermediary object to encapsulate series between objects. Mediator so that all objects do not explicitly refer to each other, so that it reduces coupling, and can independently change the interaction between them. Mediator pattern generally used between the need for a set of well-defined objects and want to customize the occasion to communicate in more than one class of behavior, but do not want the 2015 Nike Free 5.0 case to generate too many subclasses.C # design patterns (18) - Mediator pattern (Mediator Pattern)