Design patterns V: Facade Pattern

Source: Internet
Author: User

/* Author: Jiangong SUN */Facade Pattern (appearance mode) provides a unique interface to a set of methods of different subsystems in an application. it's widely used in application development. it's a structural pattern. now let's see the implementation in CSharp. firstly, create subsystems and their methods. class SubSytemOne {public void MethodOne () {Console. writeLine ("SubSystemOne Method");} class SubSy TemTwo {public void MethodTwo () {Console. writeLine ("SubSystemTwo Method") ;}} class SubSytemThree {public void MethodThree () {Console. writeLine ("SubSystemThree Method");} class SubSytemFour {public void MethodFour () {Console. writeLine ("SubSystemThree Method");} Create Facade class and its methods as an interface to subsystems 'methods' aggregation. class Facade {private readonly SubS YtemOne _ one; private readonly SubSytemTwo _ two; private readonly SubSytemThree _ three; private readonly SubSytemFour _ four; public Facade () {_ one = new SubSytemOne (); _ two = new SubSytemTwo (); _ three = new SubSytemThree (); _ four = new SubSytemFour ();} public void MethodA () {Console. writeLine ("MethodA ():"); _ one. methodOne (); _ three. methodThree ();} public void MethodB () {Console. writeLine ("Met HodB (): "); _ two. methodTwo (); _ four. methodFour ();} public void MethodC () {Console. writeLine ("MethodC ():"); _ one. methodOne (); _ two. methodTwo (); _ four. methodFour () ;}} The clients can call facade's methods to satisfy its requirements. var facade = new Facade (); facade. methodA (); facade. methodB (); facade. methodC (); So this is the implementation of facade pattern. I hope you enjoy this article. enjo Y coding!

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.