`
bjsunrose
  • 浏览: 53829 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

23-13,适配器模式

 
阅读更多
1、适配器模式(Adapter Pattern)的定义如下:
  Convert the interface of a class into another interface clients expect. Adapter lets classes work together thar couldn't otherwise because of incompatible interfaces(将一个类的接口变换成客户端所期待的另一种接口,从而是原本因接口不匹配而无法在一起工作的两个类能够在一起工作。)
  适配器模式又叫变压器模式,也叫包装模式(Wrapper),但是包装模式不止一个,还有装饰模式。

2、适配器的角色
  一、Target-目标角色
  该角色定义把其他类转化为何种接口,也就是我们的期望接口
  二、Adaptee-源角色
  你想把谁转化成目标角色。
  三、Adapter-适配器角色
  适配器模式的核心角色,其他两个角色都是已经存在的角色。适配器角色是需要新建立的角色,他的职责非常简单:就是把源角色转化成目标角色
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics