Design pattern of the façade mode

Source: Internet
Author: User

The façade pattern of the design pattern is a very easy to understand pattern, a bit like the adapter pattern, but unlike the façade pattern, it focuses on reducing complexity and providing a unified encapsulation interface.

Façade mode also has the Appearance mode, provides a consistent interface for a set of interfaces in the subsystem, and the façade pattern defines a high-level interface, which makes the subsystem easier to use.

The façade mode refers to the division of the system in order to reduce the complexity according to certain rules in the design.

Simply put, in general, the client program in the use of subsystems, may be like:

In the above implementation method, the customer class needs to master the interface is many, the subsystem changes after the client may need to follow up in a timely manner, the coupling between the system is too strong, very inconvenient to use, and the façade mode of the solution is:

The façade mode, through the maintenance of the façade role, reduces the coupling between the client program and the subsystem, and improves the code security.

A typical application for façade mode is database connectivity. In general, every time we access the database, we have to do something: Get the Connect instance first, then open connect to get the connection, get a statement, execute the SQL statement to query, get the query result.

We can extract these steps and encapsulate them in a class. In this way, every time a database access is performed, only the necessary parameters must be passed down.

Design pattern of the façade mode

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.