Agile Software Development –facade mode and mediator mode

Source: Internet
Author: User

Facade mode

The DB class makes the application class unnecessary to understand the internal details in the System.Data namespace. It hides all the versatility and complexity of the system.data behind a very simple and specific interface.

The facade class like DB imposes a number of protocols on the use of System.Data. It knows how to initialize and close the database connection. It knows how to convert a productdata member variable into a database field, or vice versa. It knows how to build the right queries and commands to manipulate the database. It hides all the complexities of the user. In application's opinion, System.Data does not exist, it hides behind the facade.

Using the facade mode means that the developer has accepted all database calls through the DB Class conventions. If any part of the code of application crosses the facade directly to access System.Data, then that Convention is violated. Like this, the facade imposed its statute on application. Based on the contract, the DB class is called the unique proxy for System.Data.

You can use facade to hide any part of the program. However, the most common practice is to use facade to hide the database, so this mode is also known as the table DATA GATEWAY.

Mediator mode

The mediator model also imposes a statute. However, the facade pattern imposes its statute in a visible and coercive manner, while the mediator pattern imposes its statute in a way that hides and cuts freely.

usingSystem;usingSystem.win.Windows.Form; Public classquickentrymediator{PrivateTextBox Itstextfield; PrivateListBox itslist;  PublicQuickentrymediator (TextBox T, ListBox l) {Itstextfield=T; Itslist=l; itstextfield.textchagned+=NewEventHandler (textfieldchanged); }    Private voidTextfieldchanged (Objectsender, EventArgs args) {String prefix=Itstextfield.gettext (); if(prefix.length () = =0) {itslist.clearselection (); return; } listbox.objectcollection ListItems=Itslist.items; Boolean found=false;  for(inti =0; Found = =false&& i < Listitems.count; i++) {Object o=Listitems[i]; String s=o.tostring (); if(S.startswith (prefix)) {itslist.setselected (I,true); Found=true; }        }        if(!found)        {itslist.clearselection (); }    }}

Users of the ListBox and TextBox do not know the existence of the mediator. It stayed quiet, imposing its statutes on those objects without their permission or knowledge.

Conclusion

If the statute covers a wide range and is visible, then the facade model can be used to apply the statute from above. On the other hand, if the scope of the statute design is small and freely customizable, then the mediator model is a better choice. The facade pattern is usually the agreed attention point. Everyone agrees to use the facade instead of the object hidden beneath it. Mediator, on the other hand, is hidden from the user. Its statute is a fait accompli rather than a contractual matter.

Excerpt from: [Mei]robertc.martin, Micahmartin, Aaron, Sun Yu translation Agile Software Development principles, patterns and practices (C # revision) [M], People's post and Telecommunications publishing house, 2013, 240-243,

Agile Software Development –facade mode and mediator mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.