C # design Pattern: Appearance mode (facade pattern)

Source: Internet
Author: User

One, what is the appearance mode?

Appearance mode: Provides a consistent interface for a set of interfaces in a subsystem, defining a high-level interface that makes this subsystem easier to use.

Two, let's look at the implementation of the Code

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespace_10. Appearance mode {  classProgram {Static voidMain (string[] args) {            //does not exist the appearance of the class is our call method is this, the following code; //people P = new people ("Chinese"); //Event E = new event (); //Console.Write (p.people); //E.say (); //appearance system, compared with the above code, we can know: The appearance mode provides a unified interface to access a group of interfaces in the subsystem. Instead of having too many instances, and also reducing the tight coupling between the client and the subsystem, such as people and event instances are not in the program.Facade FA =NewFacade ("Chinese"); Fa.            Whoevent (); Facade FA1=NewFacade ("American"); Fa1.            Whoevent ();        Console.read (); }    }    /// <summary>    ///Appearance class/// </summary>     Public classFacade {PrivateEvent EV {Get;Set; } PrivatePeople PE {Get;Set; }  PublicFacade (stringpeople) {EV=NewEvent (); PE=Newpeople (people); }         Public voidwhoevent () {Console.Write (pe.people); Ev.            Say (); Ev.        Eat (); }    }     /// <summary>     ///equivalent to the behavioral subsystem/// </summary>     Public classEvent { Public voidSay () {Console.Write ("Talk and"); }         Public voidEat () {Console.WriteLine ("Eat"); }    }    /// <summary>    ///equivalent to the human subsystem/// </summary>     Public classpeople { Public stringPeople {Get;Set; }  PublicPeople (stringp) { This. People =p; }    }}

Third, in the above code, our code structure is: client--"facade--" N Subsystems (people and event, etc.)

1 "In the appearance mode, we completely put the instance of the subsystem into the appearance, here we can provide a always-on interface, the client can directly through the appearance class to invoke the internal subsystem method, and avoids the coupling

Four, what is the difference between the appearance mode and the adapter mode?

Adapter: Adapter Adapter mode is used to combine two incompatible classes

Appearance mode: Provides a consistent interface for a set of interfaces in a subsystem

According to the above two explanations we can know:

1 "Adapter is for a single object, and the appearance mode is for multiple objects (subsystems)

2 adapter is an interface adaptation to a single object, enabling existing classes to match the results of the current system

3 "While the appearance mode is to wrap the interfaces of multiple subsystems to reduce coupling and common invocation, and the intent of the adapter mode is not the same

C # design Pattern: Appearance mode (facade pattern)

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.