11. Appearance mode (facade pattern)

Source: Internet
Author: User

usingSystem;namespaceconsoleapplication4{classProgram {/// <summary>        ///situations where the appearance mode is not used///at this point the client and three subsystems are sent a coupling, so that the client program depends on the subsystem///to solve this problem, we can use the appearance pattern to design a unified interface for all subsystems .///The client only needs to invoke the method in the skin class, which simplifies the operation of the client///So that tight coupling between the customer and the subsystem is avoided/// </summary>        /// <param name= "args" ></param>        Static voidMain (string[] args) {Subsystema a=NewSubsystema (); Subsystemb b=NewSubsystemb (); SUBSYSTEMC C=NewSUBSYSTEMC ();             A.methoda ();             B.methodb ();             C.METHODC ();        Console.read (); }    }    //subsystem a     Public classSubsystema { Public voidMethodA () {Console.WriteLine ("method A in the execution subsystem a"); }    }    //Subsystem B     Public classSubsystemb { Public voidMethodB () {Console.WriteLine ("Execute method B in subsystem b"); }    }    //Subsystem C     Public classSUBSYSTEMC { Public voidmethodc () {Console.WriteLine ("method C in the execution subsystem C"); }    }}
usingSystem;namespaceconsoleapplication4{classProgram {Private StaticRegistrationfacade facade =NewRegistrationfacade (); /// <summary>        ///situations where the appearance mode is not used///at this point the client and three subsystems are sent a coupling, so that the client program depends on the subsystem///to solve this problem, we can use the appearance pattern to design a unified interface for all subsystems .///The client only needs to invoke the method in the skin class, which simplifies the operation of the client///So that tight coupling between the customer and the subsystem is avoided/// </summary>        /// <param name= "args" ></param>        Static voidMain (string[] args) {facade. Registersystem (1); Façade. Registersystem (2); Façade. Registersystem (3);        Console.read (); }    }     Public classRegistrationfacade {PrivateSubsystema Registrationa; PrivateSubsystemb registrationb; PrivateSUBSYSTEMC Registrationc;  PublicRegistrationfacade () {Registrationa=NewSubsystema (); REGISTRATIONB=NewSubsystemb (); Registrationc=NewSUBSYSTEMC (); }         Public voidRegistersystem (inttype) {            if(Type = =1) {Registrationa.methoda (); }            Else if(Type = =2) {Registrationb.methodb (); }            Else if(Type = =3) {registrationc.methodc (); }        }    }    //subsystem a     Public classSubsystema { Public voidMethodA () {Console.WriteLine ("method A in the execution subsystem a"); }    }    //Subsystem B     Public classSubsystemb { Public voidMethodB () {Console.WriteLine ("Execute method B in subsystem b"); }    }    //Subsystem C     Public classSUBSYSTEMC { Public voidmethodc () {Console.WriteLine ("method C in the execution subsystem C"); }    }}

11. 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.