Reprint reference: http://www.cnblogs.com/V1haoge/p/6484128.html
1. Introduction of Appearance mode
The appearance pattern, commonly used between subsystem and access, is used for complex subsystem calls to access masks, and the simple invocation method provided by the refreshing appearance class is adopted, and the concrete implementation is called by the appearance class to the subsystem.
Appearance mode is still a type of middleware mode, using the appearance mode after the subsystem's method call is not completely shielded, just for the visitor provides a better way to access, if you are not too troublesome, still can directly make the subsystem method call.
Even when calls are made between subsystems and subsystems, they can be invoked through their own appearance classes, which makes the code easy to manage.
Here's a look at the code example: better to show this situation
Subsystem Method 1
Public class SubMethod1 {2 Public void method1 () {3 System.out.println ("Method 1 of Class 1 in the Subsystem"); 4 }5}
Subsystem Method 2
Public class SubMethod2 {2 Public void method2 () {3 System.out.println ("Class 2 Method 2" in the subsystem); 4 }5}
Subsystem Method 3
Public class SubMethod3 {2 Public void method3 () {3 SYSTEM.OUT.PRINTLN ("Subsystem Class 3 Method 3"); 4 }5}
Appearance class:
Public classFacader {PrivateSubMethod1 SM1 =NewSubMethod1 (); PrivateSUBMETHOD2 SM2 =NewSubMethod2 (); PrivateSubMethod3 SM3 =NewSubMethod3 (); Public voidfacMethod1 () {sm1.method1 (); SM2.METHOD2 (); } Public voidfacMethod2 () {sm2.method2 (); Sm3.method3 (); Sm1.method1 (); }}
Test class:
Public class Clienter { publicstaticvoid main (string[] args) { new Facader (); Face.facmethod1 (); // face.facmethod2 (); }}
In fact, the direct call will also get the same results, but the use of the appearance of the code can be standardized, the appearance of the subsystem is a total external interface, we want to access the subsystem is, directly to the subsystem corresponding to the appearance of the class to access it!
2. Appearance mode application scenario
When we access the subsystem has a complex amount of structure, internal calls complicated, the initial contact is not at all, uncommon by the senior person for this subsystem design an appearance class for visitors to use, unified access path (centralized to the appearance class), the complex calls together to form a total call to write to the appearance class, After that, the visitor does not need to look for the method in the complex method to call, directly in the appearance class to find the corresponding method to call.
There is also a call between the system and the system, you can also design the appearance class for the called subsystem, so that convenient call also, shielding the complexity of the system.
"Appearance mode" and application scenario of Java design pattern