Appearance mode (facade), a set of interfaces of a subsystem provides a consistent interface that defines a high-level interface that makes this subsystem easier to use.
The appearance pattern perfectly embodies the principle of dependence reversal, the idea of Dimitri Law, one of the formula.
The appearance pattern structure diagram is as follows:
Define three subsystem classes
Public classSubsystemone { Public void MethodOne() {System. out. println ("Subsystem Method 1"); }} Public classSubsystemtwo { Public void Methodtwo() {System. out. println ("Subsystem Method 2"); }} Public classSubsystemthree { Public void Methodthree() {System. out. println ("Subsystem Method 3"); }}
Define a skin facade class
public Class facade {private subsystemone one; private Subsystemtwo; private Subsystemthree three; public facade () {One =new subsystemone (); Two=new subsystemtwo (); Three=new subsystemthree (); } public void MethodA () {one.methodone (); Three.methodthree (); } public void MethodB () {one.methodone (); Two.methodtwo (); }}
Client code
publicstaticvoidmain(String[] args) { Facade facade=new Facade(); facade.methodA(); facade.methodB();}
Because of the role of the facade class. Client can not know the existence of three subsystems at all
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Design mode (facade) status (caveats)