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

推荐订阅源

V
Vulnerabilities – Threatpost
U
Unit 42
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
F
Full Disclosure
月光博客
月光博客
Engineering at Meta
Engineering at Meta
博客园_首页
The Register - Security
The Register - Security
G
Google Developers Blog
The Cloudflare Blog
博客园 - Franky
K
Kaspersky official blog
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
NISL@THU
NISL@THU
AI
AI
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Vercel News
Vercel News
T
Tor Project blog
P
Privacy International News Feed
D
Docker
I
Intezer
L
LangChain Blog
P
Proofpoint News Feed
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
博客园 - 聂微东
AWS News Blog
AWS News Blog
Martin Fowler
Martin Fowler
P
Privacy & Cybersecurity Law Blog
V
V2EX
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
The Hacker News
The Hacker News
T
Tenable Blog
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog

博客园 - 心雨无痕

升级openssl和openssh linux配置LVM 杂七杂八 .net程序包含webbrowser插件时遇到的各种问题 mysql连接远程服务器很慢的解决方法 centos安装php需要注意的问题 centos配置nfs杂七杂八 iptables配置网络端口转发 桥接模式 单例模式 原型模式 工厂方法模式 简单工厂模式 建造者模式 ActionScript中Object和Dictionary的区别 FlashBuilder4.5破解方法 抽象工厂模式 设计模式浅见 了解下常见的开源协议
适配器模式
心雨无痕 · 2012-07-16 · via 博客园 - 心雨无痕

适配器模式适用于在已有固定的不能更改或者很难更改现有接口的情况下,对现有接口进行再次封装以适应新的需求的场合。该种模式在类库迁移方面用的很多。

适配器模式概述

适配器模式分为3个角色,用户需要的接口IA,原有类库提供服务的类B,适配器Adapter,适配器模式有两种实现方式:

1. 类实现方式:适配器Adapter继承服务类B并且实现接口IA,在Adapter类实现IA的接口方法中调用类B的服务来实现服务B到IA的迁移。

2. 对象实现方式:适配器Adapter包含一个类B的对象OB为其私有变量,实现接口IA,在其实现IA的接口方法中调用其私有变量OB的方法来实现服务B到IA的迁移。

上述两种方法都可以实现接口迁移和转变的目的,但是第一种实现方法直接使用类继承的方式,增加了和原来类库代码的耦合,不符合代码解耦的原则,因此使用第二种方式为较优选择。