This is the 16th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

An overview of the

The Facade Pattern provides a unified Facade for a set of subsystems for external access, so it is also called the Facade Pattern, which is an object structure Pattern.

The facade reduces system complexity by introducing facade roles and decouples client classes from subsystems. For example, Zhang SAN runs a kettle factory, which needs to be polished and painted. Customers only need to be informed of the needs of the kettle, not the specific details of the grinding and painting. The client told us that the appearance role, polishing and painting are subsystem roles.

structure

  • Facade: Provides clients with a unified access method for multiple subsystems. It holds multiple subsystem objects through which client requests are completed.
  • SubSystem (SubSystem role) : There may be one or more SubSystem roles. Each SubSystem may not be a single class, but a collection of classes that implement the functions of the SubSystem; Each subsystem can be called directly by the client or by the facade role, which handles requests passed by the facade class. The subsystem is unaware of the facade; to the subsystem, the facade role is just another client.

advantages

  1. Loose coupling between the client and the subsystem is realized, and the client can use the subsystem or directly use the facade class. Changes to the subsystem do not affect the client, just tweak the appearance class.
  2. The system maintainability is improved. The change of one subsystem does not cause the change of other subsystems and can be maintained independently. Also, changes within the subsystem do not affect appearance objects.
  3. Facade roles provide access to a set of objects to make the system easier to use.

disadvantages

  1. If the facade class is not abstracted, adding subsystems will result in modifications to the facade class that violate the open close principle.
  2. The client’s direct use of the subsystem is not well restricted.

Application scenarios

  1. Provide a simple external access to a complex module or subsystem.
  2. There are dependencies between the client program and multiple subsystems, which are relatively independent, and external access to the subsystem is only a black box operation.

Applications in the JDK

In JDK Java. Lang. Class, Java. Util. Logging. Try to use the appearance that the LogManager mode. Java. Util. Logging. Is that the LogManager appearance character, the other is subsystem