当前位置:网站首页>Appearance mode (facade)
Appearance mode (facade)
2022-06-26 13:06:00 【baboon_ chen】
Reference resources :
Design pattern ( Facade mode ) (refactoringguru.cn)
[ Appearance mode (Facade Pattern ) Detailed explanation (biancheng.net)](http://c.biancheng.net/view/1366.html)
design-patterns-cpp/facade at master · JakubVojvoda/design-patterns-cpp · GitHub
One 、 What is the appearance mode ?
Definition : Provide a consistent interface for multiple complex subsystems , This makes these subsystems more accessible , It's also called
Facade mode.
It is equivalent to inserting an intermediate layer between the caller and the interface provider , Packaging common logic , Provide API Interface . So that users can only care about how to use , Don't worry about how complicated the process is .
such as , During telephone shopping , The customer only needs to place an order by telephone , It is not necessary for him to understand the process from shipment to receipt . This simplifies the shopping process for all customers , It also makes shopping more efficient .

Two 、 Realization
appearance (Facade) The pattern includes the following main characters :
- appearance (Facade): Provide a common interface for multiple subsystems .
- Subsystem (Sub System): Realize some functions of the system , Customers can access it through the facade role .
- Customer (Client): Access the functions of each subsystem through a look and feel role .

Facade.cpp
/*
* C++ Design Patterns: Facade
* Author: Jakub Vojvoda [github.com/JakubVojvoda]
* 2016
*
* Source code is licensed under MIT License
* (for more details see LICENSE)
*
*/
#include <iostream>
/*
* Subsystems
* implement more complex subsystem functionality
* and have no knowledge of the facade
*/
class SubsystemA
{
public:
void suboperation()
{
std::cout << "Subsystem A method" << std::endl;
// ...
}
// ...
};
class SubsystemB
{
public:
void suboperation()
{
std::cout << "Subsystem B method" << std::endl;
// ...
}
// ...
};
class SubsystemC
{
public:
void suboperation()
{
std::cout << "Subsystem C method" << std::endl;
// ...
}
// ...
};
/*
* Facade
* delegates client requests to appropriate subsystem object
* and unified interface that is easier to use
*/
class Facade
{
public:
Facade() : subsystemA(), subsystemB(), subsystemC() {}
void operation1()
{
subsystemA->suboperation();
subsystemB->suboperation();
// ...
}
void operation2()
{
subsystemC->suboperation();
// ...
}
// ...
private:
SubsystemA *subsystemA;
SubsystemB *subsystemB;
SubsystemC *subsystemC;
// ...
};
int main()
{
Facade *facade = new Facade();
facade->operation1();
facade->operation2();
delete facade;
return 0;
}
3、 ... and 、 Advantages and disadvantages , Applicable scenario
advantage
- Reduce the coupling between the subsystem and the client , So that changes to the subsystem do not affect the client class that invokes it .
- Shielding subsystem components from customers , It reduces the number of objects handled by customers , And make it easier to use the subsystem .
shortcoming
- Adding a new subsystem may need to modify the appearance class or the client's source code , Against the principle of opening and closing .
边栏推荐
猜你喜欢

el-form-item 包含两个input, 校验这两个input

Explain C language 10 in detail (C language series)
What should the software test report include? Interview must ask

Detailed explanation of C const: definition and use of C constant
![[BSidesCF 2019]Kookie 1](/img/22/585d081668e67b8389a1b90aaebe9d.png)
[BSidesCF 2019]Kookie 1

Electron official docs series: Get Started

国标GB28181协议EasyGBS视频平台TCP主动模式拉流异常情况修复

Echart堆叠柱状图:色块之间添加白色间距效果设置

Power Designer - Custom Comment button

解中小企业之困,百度智能云打个样
随机推荐
别乱用 FULL_CASE 和 PARALLEL_CASE
Software testing - Fundamentals
mariadb学习笔记
Go structure method
KVM video card transparent transmission -- the road of building a dream
Vivado 错误代码 [DRC PDCN-2721] 解决
POJ 3070 Fibonacci
四类线性相位 FIR滤波器设计 —— MATLAB源码全集
Opencv high speed download
Power Designer - Custom Comment button
中科软外包一面
Common creation and usage of singletons
倍福NC轴状态转移图解析
倍福PLC旋切基本原理和应用例程
map 取值
5月产品升级观察站
桥接模式(Bridge)
Solution of Splunk iowait alarm
数字信号处理——线性相位型(Ⅰ、Ⅲ型)FIR滤波器设计(1)
Explain C language 11 in detail (C language series)