6.适配器模式
来源:互联网 发布:union在sql中的意思 编辑:程序博客网 时间:2024/06/15 18:48
介绍
由于应用环境的变化(例如使用语言的变化),我们需要的实现在新的环境中没有现存对象可以满足,但是其他环境却存在这样现存的对象。那么如果将“将现存的对象”在新的环境中进行调用呢?使得新环境中不需要去重复实现已经存在了的实现而很好地把现有对象(指原来环境中的现有对象)加入到新环境来使用。
核心要点
“把一个类的接口变换成客户端所期待的另一种接口,从而使原本接口不匹配而无法一起工作的两个类能够在一起工作”
例子
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 适配器模式{ class Target { public virtual void Request() { Console.WriteLine("Called Target Request"); } } class Adapter:Target { private Adaptee adaptee = new Adaptee(); public override void Request() { //Todo something adaptee.SpecificRequest(); } } class Adaptee { public void SpecificRequest() { Console.WriteLine("Called SpecificRequest"); } }} //使用方法using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 适配器模式{ class Program { static void Main(string[] args) { Target target = new Adapter(); target.Request(); Console.ReadKey(); } }}
例子:二转换为三箱插头,将高电压转换为低电压等
阅读全文
0 0
- 6. 适配器模式
- 6.适配器模式
- 6. PHP之适配器模式
- 适配器及适配器模式
- 适配器及适配器模式
- 适配器模式(类适配器)
- 适配器模式(默认适配器)
- 适配器模式(对象适配器)
- 适配器模式-类适配器
- 适配器模式-对象适配器
- 深入设计模式-6.适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- 适配器模式
- UML常用图的几种关系的总结
- [乐意黎原创]CentOS里VSFTPD指定ftp 根目录的配置
- 关于Eclipse新建Android环境下的百度地图工程学习经验总结
- java实现 HTTP/HTTPS请求绕过证书检测代码实现
- C#常用工具类——Excel操作类
- 6.适配器模式
- Centos启动nginx
- Kotlin基础教程-枚举类
- 脉冲云之持续集成(下篇)
- SQL Exception
- 从framework获取context
- 在旋转之后的已排序数组中查找一个数字
- 多线程练习程序 之 模拟火车票售票系统01版
- 《JAVA与模式》之单例模式