Tomcat system architecture and Design pattern, part 2nd: Design Pattern Analysis

Source: Internet
Author: User
Tags tomcat

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.