Home>Article>Backend Development> The role of appearance mode

The role of appearance mode

藏色散人
藏色散人 forward
2019-04-16 10:00:45 6759browse

Appearance mode (facade mode)

Appearance mode refers to the packaging of appearance so that the application can only see the appearance object, but not the appearance object. to specific detail objects, which will undoubtedly reduce the complexity of the application and improve the maintainability of the program.

Advantages of the facade pattern

1. It shields the subsystem components from the customer, thereby reducing the number of objects processed by the customer and making the subsystem more convenient to use.

2. Achieves a loose coupling relationship between subsystems and customers

3. If applications need it, it does not restrict them from using subsystem classes. Therefore, you can choose between system ease of use and usability

Applicable scenarios of facade mode

1. Provide a set of interfaces for some complex subsystems

2. Improve the independence of subsystems

3. In a hierarchical structure, you can use the facade pattern to define the interface of each layer of the system

For example, when we develop a website There are the following functions

We can implement and package the three functions of closing and opening the website, closing and opening the blog, and closing and opening the registration.

webSet = new webSet(); $this->blogSet = new blogSet(); $this->registerSet = new registerSet(); } //设置共开关 - 开 public function turnOn(){ $this->webSet->start(); $this->blogSet->start(); $this->registerSet->start(); } //设置共开关 - 关 public function turnOff(){ $this->webSet->stop(); $this->blogSet->stop(); $this->registerSet->stop(); } } //调用 $Facade = new Facade(); $Facade->turnOn();

The above is the detailed content of The role of appearance mode. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:hcoder.net. If there is any infringement, please contact admin@php.cn delete