The façade pattern, also called the facade pattern, hides the complexity of the system and provides the client with an interface to access the system. This type of design pattern is a structured pattern that adds an interface to an existing system to hide the complexity of the system, providing a unified high-level access interface for a set of interfaces in a subsystem that makes subsystems easier to access or use. This pattern involves a single class that provides a simplified approach to client requests and a delegate invocation of existing system class methods.
In short, there are three roles in the design pattern of encapsulating a complex flow of processes into an interface that provides a simpler use for the user:
1 façade role (façade): This is the centerpiece of the façade model. It is called by the client role, so it is familiar with the functions of the subsystem. Within it, several functional combinations are scheduled based on the requirements of the customer role.
2 Subsystem Role (SUBSYSTEM): implements the subsystem function. For it, the façade role is as unknown as the customer role, and it does not have any façade role information and links.
3 customer role: invoke the façade role to complete the function to be obtained.
Here's a simple implementation example:
Defines a unified entry public
class Shapemaker {
private Shape circle;
private Shape Rectangle;
Private Shape Square;
Public Shapemaker () {
circle = new Circle ();
Rectangle = new Rectangle ();
Square = new Square ();
}
public void Drawcircle () {
circle.draw ();
}
public void DrawRectangle () {
rectangle.draw ();
}
public void Drawsquare () {
square.draw ();
}
}
Direct use of previously defined appearance classes to draw various shapes, as to how to get, how to draw without paying attention to public
class Facadepatterndemo {public
static void Main (string[] args) {
Shapemaker shapemaker = new Shapemaker ();
Shapemaker.drawcircle ();
Shapemaker.drawrectangle ();
Shapemaker.drawsquare ();
}
Figure 1:UML Diagram
Class Drawerone {public
void open () {
System.out.println ("First drawer was opened");
Getkey ();
}
public void Getkey () {
System.out.println ("Get the key to the second drawer")
;
}
Class Drawertwo {public
void open () {
System.out.println ("second drawer was opened");
GetFile ();
}
public void GetFile () {
System.out.println ("Get this important file");
}
Class Drawerfacade {
Drawerone darwerone = new Drawerone ();
Drawertwo darwertwo = new Drawertwo ();
public void Open () {
darwerone.open ();
Darwertwo.open ();
}
public class Drawerclient {public
static void Main (string[] args) {
Drawerfacade drawer = new Drawerfacade ();
drawer.open ();
}
Facade Mode usage Scenario:
(1) provides the outside access module for the complex module or the subsystem.
(2) The subsystem is relatively independent.
(3) In a hierarchical structure, you can use the appearance pattern to define the entry of each layer in the system.
The above is a small set to introduce the Java design pattern of the façade model (appearance mode), I hope to help you!