设计模式(七)Adapter Pattern适配器模式
适用场景:旧系统的改造升级
实际场景:java.io.InputStreamReader(InputStream)等
1.一个被适配的类
package com.littlepage.AdapterPattern;
/*
* 被适配的类
*/
public class Adaptee {
public void request(){
System.out.println("对应可实现功能");
}
}
2.客户端
package com.littlepage.AdapterPattern;
/*
* 客户端
*/
public class Client {
public void test1(Target t){
t.handleReq();
}
public static void main(String[] args) {
Client c=new Client();
Target t=new Adapter2(new Adaptee());
c.test1(t); }
}
3.适配器写法1
package com.littlepage.AdapterPattern;
/*
* 适配器本身
*/
public class Adapter extends Adaptee implements Target { @Override
public void handleReq() {
super.request();
} }
适配器写法2
package com.littlepage.AdapterPattern;
public class Adapter2 implements Target{
private Adaptee adaptee;
public Adapter2(Adaptee adaptee) {
this.adaptee = adaptee;
}
@Override
public void handleReq() {
adaptee.request();
}
}
UML图

设计模式(七)Adapter Pattern适配器模式的更多相关文章
- 设计模式——Adapter Pattern 适配器模式
我第一次接触设计模式,选取了四大类型里面的结构型,这类型的特点是关注类&对象之间的组合(使用继承),我从中选取适配器模式来具体学习. 一.适配器模式(Adapter Pattern)定义: 适 ...
- 设计模式之Adapter(适配器模式)
1.出现原因: 在软件系统中,由于应用环境的变化,常常需要将“一些现存的对象”放在新的环境中应用,但是新环境要求的接口是这些现存对象所不满足的.(所以可以在他们之间建立一个适配器的中间类) 2.意图: ...
- 设计模式(七): 通过转接头来观察"适配器模式"(Adapter Pattern)
在前面一篇博客中介绍了“命令模式”(Command Pattern),今天博客的主题是“适配器模式”(Adapter Pattern).适配器模式用处还是比较多的,如果你对“适配器模式”理解呢,那么自 ...
- .NET设计模式(8):适配器模式(Adapter Pattern)
):适配器模式(Adapter Pattern) 适配器模式(Adapter Pattern) --.NET设计模式系列之八 Terrylee,2006年2月 概述 在软件系统中,由于应用环境的 ...
- 24种设计模式--适配器模式【Adapter Pattern】
今天讲适配器模式,这个模式也很简单,你笔记本上的那个拖在外面的黑盒子就是个适配器,一般你在中国能用,在日本也能用,虽然两个国家的的电源电压不同,中国是 220V,日本是 110V,但是这个适配器能够把 ...
- 乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
原文:乐在其中设计模式(C#) - 适配器模式(Adapter Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 适配器模式(Adapter Pattern) 作者:webabc ...
- 【设计模式】适配器模式 Adapter Pattern
适配器模式在软件开发界使用及其广泛,在工业界,现实中也是屡见不鲜.比如手机充电器,笔记本充电器,广播接收器,电视接收器等等.都是适配器. 适配器主要作用是让本来不兼容的两个事物兼容和谐的一起工作.比如 ...
- C#设计模式之六适配器模式(Adapter Pattern)【结构型】
一.引言 从今天开始我们开始讲[结构型]设计模式,[结构型]设计模式有如下几种:适配器模式.桥接模式.装饰模式.组合模式.外观模式.享元模式.代理模式.[创建型]的设计模式解决的是对象创建的问题,那[ ...
- NET设计模式 第三部分 结构型模式(7):适配器模式(Adapter Pattern)
适配器模式(Adapter Pattern) ——.NET设计模式系列之八 Terrylee,2006年2月 概述 在软件系统中,由于应用环境的变化,常常需要将“一些现存的对象”放在新的环境中应用,但 ...
随机推荐
- zabbix 监控项(key)
Key 描述 返回值 参数 详细说明 agent.hostname 返回被监控端名称 字符串 - 返回配置文件中配置的被监控端的名称 agent.ping 检测被监控端是否存活 1 - 运行中 其他 ...
- 自写Jquery插件 Combobox
原创文章,转载请注明出处,https://www.cnblogs.com/GaoAnLee/p/9092421.html 上效果 html <span id='combobox' class=' ...
- Tomcat启动报错:[The configuration may be corrupt or incomplete]的解决方案
1,场景说明: 偶然碰见Tomcat启动报错,此时并没有Add任何Web项目: Could not load the Tomcat server configuration at /Servers/T ...
- Access is denied (user is anonymous); redirecting to authentication entry point
Access is denied (user is anonymous); redirecting to authentication entry point org.springframework. ...
- ssh-keygen 命令
功能 生成.管理和转换认证密钥,包括 RSA 和 DSA 两种密钥,密钥类型可以用 -t 选项指定.如果没有指定则默认生成用于SSH-2的RSA密钥,系统管理员还可以用它产生主机密钥. 通常,这个程序 ...
- 09:vuex组件间通信
1.1 vuex简介 官网:https://vuex.vuejs.org/zh/guide/ 参考博客:https://www.cnblogs.com/first-time/p/6815036.htm ...
- tf.argmax()以及axis解析
首先,明确一点,tf.argmax可以认为就是np.argmax.tensorflow使用numpy实现的这个API. 简单的说,tf.argmax就是返回最大的那个数值所在的下标. 这个 ...
- Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- iOS开发 -------- 九宫格坐标计算
一 要求 完成下面的布局 二 分析 寻找规律,每一个UIView的x坐标和y坐标 三 实现思路 (1) 明确每一块用得是什么View; (2) 明确每个View之间的父子关系,每个视图都只有一个父视图 ...