Facade design Pattern
The façade design pattern is used in multiple places in Tomcat, in Request and Response object encapsulation, Standard wrapper to ServletConfig encapsulation, ApplicationContext to ServletContext This design pattern is used in the packaging medium.
The principle of the façade design pattern
This design pattern is used on so many occasions, so what can this design pattern do? As the name suggests, is to encapsulate a thing into a façade it is easier to communicate with others, just like the foreign Ministry of a country.
This design pattern is mainly used in a large system with multiple subsystems, which must involve communicating with each other, but each subsystem can not expose its internal data too much to other systems, otherwise there is no need to partition the subsystem. Each subsystem designs a façade that encapsulates data of interest to other systems and accesses it through the façade. This is the meaning of the façade design pattern.
The schematic diagram of the façade design pattern is as follows:
Figure 1. Façade schematic
The client can only access the data provided in the Façade is the key to the façade design pattern, as to how the client accesses Façade and subsystem how to provide the Façade façade design pattern does not specify death.
Example of Tomcat's façade design pattern
The Tomcat design pattern is used a lot because Tomcat has many different components, each of which interacts with the data, and it's a good way to isolate the data with a façade pattern.
Here is the façade design pattern used on the Request:
Figure 2. Request of the façade design pattern class diagram
As you can see from the diagram, the Httprequestfacade class encapsulates the HttpRequest interface to provide data, and the data accessed through the Httprequestfacade is represented in HttpRequest, and usually the encapsulated object is set to Private or Protected access adornments to prevent direct access in Façade.