当前位置:网站首页>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 .
边栏推荐
- 详细讲解C语言11(C语言系列)
- Digital signal processing -- Design of linear phase type (Ⅰ, Ⅲ) FIR filter (1)
- 解中小企业之困,百度智能云打个样
- Verilog中的系统任务(显示/打印类)--$display, $write,$strobe,$monitor
- [esp32-C3][RT-THREAD] 基于ESP32C3运行RT-THREAD bsp最小系统
- 倍福PLC选型--如何看电机是多圈绝对值还是单圈绝对值编码器
- 中国剩余定理模板题 互质与非互质
- ES6:Map
- 倍福PLC旋切基本原理和应用例程
- P2393 yyy loves Maths II
猜你喜欢
openlayers 绘制动态迁徙线、曲线
Electron official docs series: Processes in Electron
goto语句实现关机小程序
【Spark】.scala文件在IDEA中几种图标的解释
Dark horse notes - Common APIs
Processing random generation line animation
倍福CX5130换卡对已有的授权文件转移操作
The El form item contains two inputs. Verify the two inputs
MySQL 自定义函数时:This function has none of DETERMINISTIC, NO SQL 解决方案
Don't mess with full_ Case and parallel_ CASE
随机推荐
【网络是怎么连接的】第二章(中):一个网络包的发出
Summary of wechat applet test points
倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用
详细讲解C语言11(C语言系列)
黑马笔记---常用API
LeetCode_栈_中等_150. 逆波兰表达式求值
[esp32-C3][RT-THREAD] 基于ESP32C3运行RT-THREAD bsp最小系统
HDU 3555 Bomb
Copy multiple Excel files and name them different
File remote synchronization and backup artifact Rsync
EasyGBS如何解决对讲功能使用异常?
Processsing mouse interactive learning
What are the common categories of software testing?
Word文档导出(使用固定模板)
tauri vs electron
Common creation and usage of singletons
[geek challenge 2019] rce me 1
Group counting practice experiment 9 -- using cmstudio to design microprogram instructions based on segment model machine (2)
postgis计算角度
自动化测试的局限性你知道吗?