Design mode-Appearance mode

Source: Internet
Author: User

Providing a consistent interface for a set of interfaces in a subsystem, the facade schema defines a high-level interface that makes this subsystem easier to use.
Image analogy: I have a professional Nikon camera, I like to manually adjust the aperture, shutter, so that the photo is professional, but mm can not understand these, taught a half day will not.   Fortunately, the camera has facade design mode, the camera to adjust the automatic file, as long as the target to press the shutter line, everything from the camera automatically adjust, so mm can also use this camera to take a picture of me. Façade mode: External communication with a subsystem must be done through a unified façade object. Façade mode provides a high-level interface that makes subsystems easier to use. Each subsystem has only one façade class, and this façade class has only one instance, meaning it is a singleton pattern. But the entire system can have multiple façade classes.facade. Java:know which subsystem classes are responsible for processing requests. The client's request is proxied to the appropriate subsystem object.
1  Public classFacade {2 ServiceA sa;3     4 SERVICEB sb;5     6 SERVICEC SC;7     8      Publicfacade () {9SA =NewServiceA ();TenSB =NewServiceB (); Onesc =Newservicec (); A     } -      -      Public voidMethodA () { the Sa.methoda (); - Sb.methodb (); -     } -      +      Public voidMethodB () { - Sb.methodb (); + sc.methodc (); A     } at      -      Public voidmethodc () { - sc.methodc (); - Sa.methoda (); -     } -}

SubsystemServiceA. Java:
    1. 1  Public class servicea{2      Public void MethodA () {3         System.out.println ("This is Service a"); 4     }5 }    

Subsystem serviceb. Java:
    1. 1  Public class ServiceB  {2public     void  MethodB () {3         System.out.println ("This is Service B"); 4     }5 }


Subsystem servicec. Java:
1  Public class SERVICEC {2      Public void methodc () {3         System.out.println ("This is Service C"); 4     }5 }

Test class:
  1. 1  Public classTest {2     3      Public Static voidMain (string[] args) {4Facade facade =Newfacade ();5 Facade.methoda ();6System.out.println ("========");7 Facade.methodb ();8     }9     Ten}


Test results: This is service aThis is service B .========This is service B .This is the service C

Design mode-Appearance mode

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.