Facade Pattern hides the complexity of the system and provides the client with an interface that the client can 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.
This pattern involves a single class that provides a simplified method of client request and a delegate call to an existing system class method.
Intent: provides a consistent interface to a set of interfaces in the subsystem. The facade mode defines a high-level interface that makes this subsystem easier to use.
Main solution: Reduces the complexity of accessing internal subsystems of complex systems and simplifies the interface with clients.
When to use: 1. The client does not need to know the complicated connection inside the system. The whole system only needs to provide a "receptionist". 2. Define the entrance to the system.
How to solve: The client is not coupled to the system, and the appearance class is coupled to the system.
Key Code: Add another layer between the client and the complex system. This layer handles the calling order, dependencies, and so on.
Application example: 1, go to the hospital to see a doctor, may have to go to the registration, outpatient, price, take medicine, so that patients or family members feel very complicated, if there is a reception staff, only the reception staff to deal with, it is very convenient. 2. JAVA's three-tier development model.
Advantages: 1. Reduce system interdependence. 2. Increase flexibility. 3. Improve safety.
Disadvantages: does not meet the principle of opening and closing. If it is troublesome to change things, inheritance and rewriting are not appropriate.
Usage scenarios: 1. Modules that provide external access to complex modules or subsystems. 2. The subsystems are relatively independent. 3. Prevent the risks brought by low-level personnel.
Note: In a hierarchical structure, you can use the Appearance mode to define the entry for each layer in the system.
We will create an Shape interface and an entity class that implements the Shape interface. The next step is to define a skin class ShapeMaker.The
ShapeMaker class uses entity classes to represent user calls to these classes. FacadePatternDemo, our demo class uses the ShapeMaker class to display the results.
Create an interface.
Create an entity class that implements the interface.
Create a skin class.
Use this skin class to draw various types of shapes.
Executing the program, outputting results:
Circle::draw< /span>() Rectangle::draw() Square::draw()