当前位置:网站首页>Structural mode - facade mode
Structural mode - facade mode
2022-07-27 04:41:00 【vbirdbest】
One : Definition
Also known as facade pattern , It is a method to provide a consistent interface through multiple complex subsystems , Patterns that make these subsystems more accessible .
This mode has a unified interface for me , External applications don't care about the details of the internal subsystem , This will greatly reduce the complexity of the application , Improved program maintainability .

Two : role
- appearance (Facade) role : Provide a common interface for multiple subsystems .
- Subsystem (Sub System) role : Realize some functions of the system , Customers can access it through the facade role .
3、 ... and : Case study
Operate all smart homes through smart audio .
public class Light {
public void on() {
System.out.println(" Turn on the light ");
}
public void off() {
System.out.println(" Turn off the lights ");
}
}
public class TV {
public void on() {
System.out.println(" Turn on the TV ");
}
public void off() {
System.out.println(" Turn off the TV ");
}
}
AISound: Artificial intelligence sound , It can control all smart appliances . Hold references to all smart appliances , Provide unified external access , And adapt to the operation of each household appliance .
public class AISound {
private Light light;
private TV tv;
public AISound() {
light = new Light();
tv = new TV();
}
public void say(String msg) {
if (msg.contains(" open ")) {
light.on();
tv.on();
} else if (msg.contains(" close ")) {
light.off();
tv.off();
}
}
}
public class Client {
public static void main(String[] args) {
AISound aiSound = new AISound();
aiSound.say(" Turn on the appliance ");
aiSound.say(" Turn off appliances ");
}
}
Four : benefits
- 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 , Reduce the object data processed by customers , And make it easier to use the subsystem .
- shortcoming :
- Inconsistent with the open and close principle , Modification is troublesome .
5、 ... and : Use scenarios
- When building the overall structure system , Using appearance pattern to define the entry point of each layer in a subsystem can simplify the dependency between subsystems .
- When there are many complex subsystems , Appearance mode can design a simple interface for the system for external access .
- When there is a large connection between the client and multiple subsystems , Introducing appearance mode can separate them , So as to improve the independence and portability of the subsystem .
边栏推荐
- 使用Unity做一个艺术字系统
- redux三大核心
- 华为入局商用市场:趋势使然,挑战颇多
- Head detached from origin/... Causes push failure
- 利用JSON类型在mysql中实现数组功能
- Easy to use shell shortcuts
- Horizon sunrise X3 PI (IV) running on board (unfinished)
- timestamp列使用varchar类型和使用date类型有什么区别?
- Redis interview question (2022)
- Shell中的文本处理工具、cut [选项参数] filename 说明:默认分隔符是制表符、awk [选项参数] ‘/pattern1/{action1}filename 、awk 的内置变量
猜你喜欢

从零开始C语言精讲篇4:数组

Convolution neural network -- convolution of gray image
![[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!](/img/26/22597a7ece0431a4e54703945a775c.jpg)
[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!

ceph操作

Do you know about wechat merchant billing?

Use unity to build a WordArt system

shel自动设置目录权限

博云容器云、DevOps 平台斩获可信云“技术最佳实践奖”

Convolution neural network -- a detailed introduction to convolution of 24 bit color images

IIC communication protocol (I)
随机推荐
Overview of communication protocols
grid布局
Ref Hook
GenericServlet为什么有两个init方法
深度学习领域图像分割FCN(Fully Convolutional Networks for Semantic Segmentation)
Explain left value, right value, left value reference and right value reference in detail
Introduction to regular expressions of shell, general matching, special characters: ^, $,., * Character range (brackets): [], special characters: \, matching mobile phone number
[hcip] redistribute, redistribute and redistribute experiments
iPhone13再降价,其实只是做做样子,消费者都在等iPhone14
timestamp列使用varchar类型和使用date类型有什么区别?
Full revolutionary networks for semantic segmentation (FCN)
Database leader Wang Shan: strive for innovation and carefully Polish high-quality database products
Yolov4 network details
[day02] Introduction to data type conversion, operators and methods
【AtCoder Beginner Contest 260 (A·B·C)】
RSA asymmetric encryption and decryption signature verification tool
博云容器云、DevOps 平台斩获可信云“技术最佳实践奖”
Okaleido tiger will log in to binance NFT in the second round, or continue to create sales achievements
Using JSON type to realize array function in MySQL
Standard C language 13