The definition of this mode is very simple to encapsulate a series of object interactions with a mediation object. Intermediaries
Enable the objects that do not need to be referenced to each other, thereby coupling their coupling, and can be independently changed
The interaction between them. What is the benefit? It is obviously to reduce complexity. Make more
Multiple relationships. Now become 1-to-many relationship. Because all objects are only single lines with Mediator intermediaries
Department. The intermediary hermit includes the relationship between the object. The following is a simple example. Such as: Xiao Wang
To give the manuscript to Xiao Li. Xiao Li wants to give the book to Xiao Zhang. Xiao Zhang wants to give the pen to Xiao Wang. And Xiao Zhang wants
Have the portable to Xiao Li. This will be more complicated if the interaction between objects and objects. If they only
It is given the item to a diploma. It is responsible for the belongings by the intermediaries. Such everyone only and the intermediary
Establish a connection. And the relationship between the intermediaries maintain the object.
/ / Start Public Interface IPerson {String Name (Get;) from the interface; ArrayList Article {Get; SET;} // Multiple items may have multiple items}
Public class Wang: iPerson {private string name = "wang"; private arraylist article;
Public string name {get {return name;}}
Public arraylist article {get {raeturn articles;}} // ....... do other things}
Public class zhang: iPerson {private string name = "zhang"; private arraylist article;
Public string name {get {return name;}}
Public arraylist article {get {raeturn articles;}} // ....... do other things}
Public class lee: iperson {private string name = "lee"; private arraylist article;
Public string name {get {return name;}}
Public arraylist article {get {raeturn articles;}} // ....... do other things}
// Mediator public interface imediator {// Exchange item Void SWEAPArticle (IPerson P1, IPerson P2, Object At);}
Public class concretemediator: iMediator {public void SWEAPArticle (IPerson P1, IPerson P2, Object At) {p1.Article.add (p2.Article [at]); p2.Article.remove (at);}}
// actually call
Public class client {public static int main (string [] args) {imediator m = new concertemediator (); iPerson Wang = new Wang (); iperson zhang = new zhang (); iperson lee = new lee (); wang.Article .Add ("manuscript"); zhang.Article.Add ("Books"); Lee.Article.Add ("Pen"); Lee.Article.Add ("Walkman");
// Exchange start M.SWeapArticle (Wang, Zhang, "Manuscript"); M.SWeapArticle (Zhang, Lee, "LEE, ZHANG," Pen "); M.SWeapArticle (Lee, Wang , "Walkman"); return 0;}}}}
The main purpose of this mode is to make a much more-to-many relationship. Getting a couple to refer to all the design patterns I wrote, please refer to the following link http://www.9cbs.net/develop/list_article.asp?author = YARSHRAY & MyClassID = 11564 & myclassname
To this, the commonly used 20 model patterns have been completed. Additional design patterns Interpreter are mainly used to analyze the language, so IITERATOR design mode can basically replace the indexof method in the IList interface, so I hope I hope These three days of efforts. You can help everyone.