设计模式之Adapter模式(笔记)
来源:互联网 发布:提词器镜像软件出错 编辑:程序博客网 时间:2024/06/05 17:34
适配器模式:将一个类的接口转移成客户希望的另外一个接口,此模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
首先定义一个目标接口ITarget
public interface ITarget { public void request();}
然后定义一个需要适配的类Adaptee
public class Adaptee { public void specialRequest(){ System.out.println("特殊请求"); }}
接着定义一个Adapter类继承 ITarget接口
public class Adapter implements ITarget{ private Adaptee adaptee=new Adaptee(); @Override public void request() { adaptee.specialRequest(); }}
客户端代码
public static void main(String[] args) { //适配器模式 ITarget target=new Adapter(); target.request();}
0 0
- 设计模式之Adapter模式(笔记)
- 设计模式(c++)笔记之七(Adapter模式)
- 设计模式实例(Lua)笔记之六(Adapter模式)
- 设计模式笔记-Adapter模式
- 设计模式之--适配器模式(adapter)
- 设计模式之Adapter(适配器模式)
- 设计模式之适配器(Adapter)模式
- 设计模式之--适配器模式(adapter)
- 设计模式之适配器模式(Adapter)
- 设计模式之--适配器模式(adapter)
- 设计模式之适配器模式(Adapter)
- 设计模式之(二)Adapter模式
- 设计模式之--适配器模式(adapter)
- 设计模式之Adapter(适配器)模式
- 设计模式之适配器模式(Adapter)
- 设计模式之(Adapter)适配器模式
- 设计模式之适配器模式(Adapter)
- 设计模式之适配器模式(Adapter)
- 第一个程序:HelloWorld
- 【伊利丹】Hadoop-2.5.0-CDH5.2.0/Hive与Hbase整合实验
- PHP调试环境搭建:wampserver2.4+zend studio12.0.1+Xdebug
- 机器学习中的相似性度量
- SVG基础 | SVG PATH 元素
- 设计模式之Adapter模式(笔记)
- xcode指令集设置
- junit 报错以及解决的办法
- 自定义注解做数据验证
- Java Keytool使用方法
- 考虑到内存覆盖的strcpy实现
- php扩展开发
- Android利用Fiddler进行网络数据抓包
- Java操作HTML格式字符串的标签和属性