当前位置:网站首页>配饰器模式
配饰器模式
2022-07-23 03:54:00 【amateur12】
将原本不兼容的接口转换为客户期望的接口,使得原本由于接口不兼容而不能一起工作的类能够一起工作
生活举例:
我们知道手机充电口有好多种,苹果的、安卓的大孔以及小孔,经常我们手机没电借了一个充电器,发现不兼容我们自己的手机孔。现在市场有有充电器的转换头,有了转换头,我们就能够去把手机充电了
角色:
目标抽象类(Target)、适配者(Adaptee)、适配器(Adaptor)
种类:
类适配器:基于继承,重新实现
对象适配器:基于组合,重新实现
种类的选择:
如果适配者中绝大部分的方法,都可以复用,那么就选择使用类适配器,否则使用对象适配器,对象适配器更加灵活
场景:
统一多个类的接口设计,比如一个支付系统,有三种不同的支付方式,微信支付、支付宝支付、余额支付,这三种支付的实现方法都不一样,那么我们可以用适配器模式,让他们对外具有统一的方法,这样,我们在调用的时候就非常的方便
兼容老版本的接口,这个在我们系统升级中经常会用到
边栏推荐
- EasyCVR平台升级到最新版本v2.5.0,如何同步mysql数据库?
- [learning notes] agc022
- These four key technologies are necessary to realize the unified management of urban governance through one network
- EasyCVR新版本(v2.5.0)目录分级功能如何使用?
- 浏览安全怎么提升?教你设置安全浏览器信任站点
- 【学习笔记】图论思维题
- Normal form and anti normal form
- 金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(八))
- Illustration and text demonstrate the movable range of the applet movable view
- 缓存穿透、缓存击穿、缓存雪崩
猜你喜欢

STM32 - input capture experiment

你离个人信息泄漏的安全距离,或许一台笔记本电脑就可以决定!

2. Judgment statement

A concise tutorial for soft exam system architecture designer | reverse engineering

QT error: error c2039 "value": not a member of "`global namespace"

Use the x2mindspire tool of mindstudio to convert training scripts

performance介绍

"Lost wake up problem" in multithreading | why do wait() and notify() need to be used with the synchronized keyword?

【车联网原型系统|二】数据库+应用层协议设计

使用MindStudio的X2MindSpore工具进行训练脚本转换
随机推荐
2022/7/20
Learn and understand Architecture Design from business development
三数之和:(排序+双指针+剪枝)
[c #] IEnumerable enumerable type interface analysis yield
MySQL queries all table names and column information of the database through SQL
ArcGIS calculates the correlation between two grid layers
【MySQL】游标「Cursor」
[azure event center] try new functions of azure event hub -- geo disaster recovery
SSH supermarket inventory management system
Use reflection to modify the member variable whose modifier is final
客户至上 | 国产BI领跑者,思迈特软件完成C轮融资
Underlying mechanism of pointer
数据中台、BI业务访谈(三):如何选择合适的访谈对象
IDEA 集成 Sonar 完整流程
"Lost wake up problem" in multithreading | why do wait() and notify() need to be used with the synchronized keyword?
These four key technologies are necessary to realize the unified management of urban governance through one network
Advantages and disadvantages of RDB and AOF
Three goals and eight tasks of intelligent construction pilot city notice
C language -- several classic exercises of C language
世界正在被开源软件吞食