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 Public class servicea{2 Public void MethodA () {3 System.out.println ("This is Service a"); 4 }5 }
Subsystem serviceb. Java:
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 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