1, appearance mode
What is the appearance pattern. The appearance pattern can be likened to the fact that we buy computers in our lives. Buy a computer we can go to the relevant computer accessories shop to buy related computer accessories, such as motherboards, memory, CPU and other accessories, we can also through some businesses to buy people assembled a good computer, here through the merchants to buy the computer is a mode of appearance. The role of the merchant masks the customer's details about assembling the computer, customers don't need to care how the computer is assembled, and the details of the Assembly computer are implemented by the vendor selling the computer, and of course we can assemble the computer ourselves, but only if we know how to assemble the computer and solve the compatibility problem between the components.
In computer systems, clients access components in the system, the client needs to know how to access the components of the system, once the interface components in the system changes, the client will also make the corresponding changes, as shown in the following figure:
However, if we add a layer of interface between the system and the client, unify the client's access interface to the system, so no matter how the component changes, for the client, the component changes are transparent, beneficial to the client and the system decoupling. The following figure:
2, code implementation
Package com.conjane.facade;
public class Client {public
static void Main (string[] args) {
new façade (). Getcomponent ()}
}
Package com.conjane.facade;
public class Façade {public
void Getcomponent () {
Modulea Modulea = new Modulea ();
Modulea.getmodule ();
Moduleb Moduleb = new Moduleb ();
Moduleb.getmodule ();
Modulec Modulec = new Modulec ();
Modulec.getmodule ();
}
Package com.conjane.facade;
public class Modulea {public
void GetModule () {
System.out.println ("Get Modulea");
}
Package com.conjane.facade;
public class Moduleb {public
void GetModule () {
System.out.println ("Get Moduleb");
}
Package com.conjane.facade;
public class Modulec {public
void GetModule () {
//TODO auto-generated method stub
System.out.println (" Get Modulec ");
}
3, the appearance pattern brings the ponder
From the direct interaction of clients and components to the interaction of client and skin objects, perhaps only the code that accesses the component moves from the client to the skin object, but such an operation masks the interaction between the external client and the system's internal modules. Although the introduction of the appearance of the object in the system, but when we want to directly access the components in the system is also accessible, not to say that with the appearance of objects, we have access to the components of the way to achieve through the appearance of objects, such operations will also provide us with some flexibility in the implementation The purpose of the façade pattern is not to add a new functional interface to the subsystem, but to allow the external to reduce the interaction of multiple modules within the subsystem, loosely coupled, so that the external subsystem can be used more simply. 4, appearance mode and other modes contrast 4.1, appearance mode and intermediary mode
The appearance pattern is between the external system and the internal system, and the mediator pattern is responsible for the interaction between the modules within the system, and is responsible for the loose coupling between the modules. 4.2, appearance mode and single case mode
Usually a subsystem requires only one instance of the façade, so the appearance pattern can be combined with a singleton pattern to implement the façade class as a single example. It is also possible to privatize the construction method of the appearance class and then implement the method provided to the client as static.