适配器模式
来源:互联网 发布:网络安全法考试单选 编辑:程序博客网 时间:2024/05/16 09:38
适配器模式:
一个笔记本需要三相插口充电,然而现在只有双相电,需要为其创建适配器。
//提供双相电public class Two(){public void chargewithTwo(){ System out println("用双相电充电") }}
//三相电接口public interface Three(){ public void chargewithThree();}
//适配器需要实现要转换的接口,并在构造函数中接收被转换的对象public class TwoToThreeAdapter implements Three(){ private Two Two; public TwoToThreeAdapter(Two two){ this.two=two; } public void chargewithThree(){ two.chargewithTwo(); }}
//笔记本public class NoteBook(){ private Three three; public NoteBook(Three three){ this.three=three; } public void charge(){ three.chargewithThree(); } public static main(String[] args){ //只提供了双相电 Two two = new Two(); //将双相电转换为三相的接口 Three three = new TwoToThreeAdapter(two); //为笔记本提供三相的接口 NoteBook book = new NoteBook(three); //为笔记本充电 book.charge(); } }
0 0
- 适配器及适配器模式
- 适配器及适配器模式
- 适配器模式(类适配器)
- 适配器模式(默认适配器)
- 适配器模式(对象适配器)
- 适配器模式-类适配器
- 适配器模式-对象适配器
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- C++标准库中的list设计
- swift开源了,iOS开发者的福音到了
- 交流电路中相位超前和滞后问题
- 奇怪的死循环
- jsp页面 URL传中文参数到Action里面出现乱码,用过滤器和控制器都解决
- 适配器模式
- Distinctive Image Features from Scale-Invariant Keypoints-SIFT算法译文
- KEIL MDK5.10开发环境安装教程(本文提供资源适用于STM32F03x/STM32F10x/STM32F4x系列控制器)
- HDU-5533-Dancing Stars on Me【2015长春赛区】
- 各种版本控制工具的使用
- 每次开机后MySQL服务都不见了需要重新开mysqld-debug的解决办法
- 维护堆性质中,堆(完全二叉树)中i结点的子树大小至多为2n/3的证明
- multiple reactors + thread pool(one loop per thread + threadpool)(突发I/O与密集计算)
- LintCode-剑指Offer-(88)最近公共祖先