Facade Patternprovide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. (Requires that the external communication of a subsystem must be done through a unified object, and that the façade mode provides a high-level interface, making the subsystem easier to use)
Why is this a design pattern?
Public interface Iletterprocess {public void Writercontext (string context), public void Fillenvelope (string address); pub LIC void Letterintoenvelope (); public void Sendletter ();}
public class Letterprocess implements iletterprocess {public void Fillenvelope (String address) { System.out.println ("Fill in the address of the letter:" +address);} public void Letterintoenvelope () { System.out.println ("Put the letter in the envelope"), public void Sendletter () { SYSTEM.OUT.PRINTLN ("postal mail"); } public void Writercontext (String context) { System.out.println ("Write content:" +context);}}
public class Modenpostoffice {private iletterprocess letterprocess=new letterprocess (); public void Sendletter (String context,string address) { This.letterProcess.writerContext (context); This.letterProcess.fillEnvelope (address); This.letterProcess.letterIntoEnvelope (); This.letterProcess.sendLetter (); }}
public class Client {public static void Main (string[] args) { modenpostoffice postoffice=new modenpostoffice (); Postoffice.sendletter ("You were admitted", "xx University");}
Flexible, packaged, secure and less dependent
Shortcomings do not conform to the opening and closing principle, no way to expand
Use scenarios to provide an external access interface subsystem for a complex subsystem or module relative independent prevention of a low level of technical personnel involved in project development, in order to reduce the impact of personal code quality on the overall project risk
I'm a rookie, I'm on my way.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Design Pattern _ Façade mode