Design Pattern 10 (appearance pattern)

Source: Internet
Author: User

Appearance mode: provides a consistent interface for a group of interfaces in the subsystem. This mode defines a high-level interface, which makes the system easier to use.

SubSystem Class sub-system Class sets implement sub-system functions to process the tasks assigned by the Facade object. Note that there is no Facade Information in the sub-Class, that is, there is no reference to the Facade object.

The first is the class of the four subsystems.

Public class SubSystemOne {public void MethodOne () {Console. writeLine ("Subsystem Method 1") ;}} public class SubSystemTwo {public void MethodTwo () {Console. writeLine ("Subsystem Method 2") ;}} public class SubSystemThree {public void MethodThree () {Console. writeLine ("Subsystem Method 3") ;}} public class SubSystemFour {public void MethodFour () {Console. writeLine ("Subsystem Method 4 ");}}

Appearance

Public class Facade {SubSystemOne one; SubSystemTwo two; SubSystemThree three; SubSystemFour four; public Facade () {one = new SubSystemOne (); two = new SubSystemTwo (); three = new SubSystemThree (); four = new SubSystemFour ();} public void MethodA () {Console. writeLine ("\ n method group A () ----"); one. methodOne (); two. methodTwo (); four. methodFour ();} public void MethodB () {Console. writeLine ("\ n method group B () ----"); two. methodTwo (); three. methodThree ();}}

Client call

    class Program    {        static void Main(string[] args)        {            Facade facade = new Facade();            facade.MethodA();            facade.MethodB();            Console.ReadLine();        }    }

The running result is as follows:

First, in the initial stage of design, we should consciously separate the two layers.

Second, in the development stage, subsystems are often increasingly complicated due to continuous reconstruction and evolution. Adding a Facade can provide a simple interface to reduce the dependency between them.

Third, it may be difficult to maintain and expand a legacy large system. A Facade class can be developed for the new system to provide clear and simple interfaces for designing rough or highly complex legacy code, so that the new system can interact with the Facade object, facade interacts with legacy code for all complex tasks.

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.