Appearance pattern Concept
Appearance mode, also known as façade mode, provides a consistent interface for a set of interfaces in a subsystem that defines a hierarchical interface that makes this subsystem easier to use. This pattern perfectly embodies the idea of relying on the reversal principle and the Dimitri rule, so it is one of the most common patterns.
Appearance mode UML diagram
Appearance Pattern Code
Learning the appearance pattern I used an example of a fight, fights generally do not want to be seen, as long as the people know to hit the can.
PackageCom.roc.face;/*** Façade mode interface fight can't be seen by others@authorLIAOWP **/ Public InterfaceFaceinterface {/*** Who to fight with *@paramname*/ Public voidFight (String name); /*** Give sugar *@paramNum*/ Public voidGivetang (intnum);}
PackageCom.roc.face;/*** Specific Implementation method *@authorLIAOWP **/ Public classFaceimlImplementsfaceinterface{/*** Fight*/ Public voidFight (String name) {System.out.println ("Hit" +name); } /*** Give sugar *@paramNum*/ Public voidGivetang (intnum) {System.out.println ("Can't get revenge, give You" +num+ "Candy"); } }
Package Com.roc.face; /** @author*/Publicclass facemodel { Private faceinterface faceinterface=new faceiml (); Public void Deal (String name,int num) { faceinterface.fight (name); Faceinterface.givetang (num); }}
PackageCom.roc.face;/*** Use scene *@authorLIAOWP **/ Public classClient { Public Static voidMain (string[] args) {Facemodel Facemodel=NewFacemodel (); String name= "LIAOWP"; Facemodel.deal (Name,1);//Do not care how to fight inside, only know to hit that person. This is the façade if now after the fight fear revenge, and gave a piece of sugar, just need to modify the interface over there on it. }}Appearance mode applicable scenario (1) The initial stage of the design should be conscious of separating the different layers and establishing the appearance pattern between the layers and the layers. (2) During the development stage, the subsystem becomes more and more complex, and the appearance mode is added to provide a simple calling interface. (3) When maintaining a large legacy system, it is possible that the system is very difficult to maintain and extend, but it also contains very important features for it to develop an appearance class so that the new system interacts with it.
Appearance mode of Java design pattern