惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
F
Full Disclosure
Cloudbric
Cloudbric
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
N
News and Events Feed by Topic
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
GbyAI
GbyAI
C
Check Point Blog
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Recorded Future
Recorded Future
The Last Watchdog
The Last Watchdog
N
News and Events Feed by Topic
T
The Blog of Author Tim Ferriss
O
OpenAI News
V
V2EX
人人都是产品经理
人人都是产品经理
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
WordPress大学
WordPress大学
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Security @ Cisco Blogs
C
Cisco Blogs
Security Latest
Security Latest
S
Security Affairs
V
Visual Studio Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
Last Week in AI
Last Week in AI
AWS News Blog
AWS News Blog
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
博客园_首页
U
Unit 42
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
L
LINUX DO - 热门话题
H
Hacker News: Front Page

博客园 - cjfwu

设计模式学习4-Bridge模式 设计模式学习3-Strategy模式 设计模式学习1-Facade模式 设备控制(反馈处理) 通过System.IO.Packaging实现打包和解包 将目录添加环境变量 设备控制之矩阵状态显示 windows shell 编程3(函数解释) windows shell 编程2(浏览文件夹) windows shell 编程1(概念) 不同命名空间下名称和结构相同的类相互序列化与反序列化 通过SvcUtil.exe生成客户端代码和配置 分组 在“添加引用”对话框中显示需要的Assembly 只运行一个实例 SVN操作 托盘操作 获得树节点的高度 枚举的操作
设计模式学习2-Adapter模式
cjfwu · 2013-03-23 · via 博客园 - cjfwu

背景描述:

在日常生活中大家有没有碰到过这种情况:墙上的插座只有3孔的,可是电器的插头是2脚的,怎么办?我的做法是找把老虎钳将插头2脚拧斜然后就可以插到3孔的插座了,哈哈。能不能不要这么粗鲁啊,好吧,找一个2孔转3脚的转换器。这个转换器就是Adapter。

Adapter模式:

定义:将一个类的接口转换成Client希望的另外一个接口。Adapter模式使原来由于接口不兼容而不能一起工作的类可以一起工作。

实现:将原有类包含在另一个类之中。让包含类与需要的接口匹配,调用被包容类的方法。

结构图:

            

说明:

  1. Adapter模式最常见的用途就是保持多态性。如结构图所示,Target接口有Request方法,它的子类需要实现Request方法,现在有个现成的类Adaptee类实现了此功能,但是它的方法名不叫Request,而是SpecificRequest,那么就在Adapter子类中包含Adaptee对象,在调用Adapter的Request方法时去调用Adaptee的SpecificRequest方法即可。
  2. Adapter模式分为对象Adapter模式和类Adapter模式2种类型。结构图中的是对象Adapter模式,因为它是一个对象(Adapter)包含另一个对象(Adaptee);类Adapter模式通过多重继承来实现。

Facade模式和Adapter模式的区别:

看起来Facade模式和Adapter模式很类似,它们都是包装,但是它们是不同类型的包装,它们的区别如下:

  1. Facade模式目的是简化接口,Adapter模式则是将一个已有的接口转换成另一个接口。
  2. Facade模式无需按某个接口进行设计,Adapter模式则必须按某个接口设计。
  3. Facade模式不需要多态行为,而Adapter模式则可能需要多态行为。