Design pattern learning II: Adapter pattern

原创 2006年05月30日 01:19:00

GoF says:
Convert the interface of a class into another interface that the clients expect. Adapter lets classes work together that could not otherwise because of incompatible interfaces.

Basicly, this is saying that wo need a way to create a new interface for an object that dose the right stuff but has the wrong interface.

Intent: Match the existing object beyond your control to a particular interface;
Solution: The Adapter provides a wrapper with the desired interface;
Consequence: The Adapter pattern allows for preexisting objects to fit into new class structures without being limited by their interfaces;
Implementation: Contain the existing class in another class. Have the containing class match the required interface and call the methods of the contained class.

Two types of Adapter patterns:
Object Adapter pattern - The Adapter pattern relies on one object containning another
Class Adapter pattern - Multiple inheritance

The difference between Facade pattern and Adapter pattern:
A facade pattern simplifies an interface while adapter pattern convert the interface into a preexisting interface.

 

//-----------------------------------------------华丽的分割线-------------------------------------------------

 

GOF说:Adapter把类的接口转换成用户想要的接口。Adapter让有着不一致的接口的类共同工作。

如果一个对象做了正确的事但是有着错误的接口,那么我们需要创建一个新的接口。

目的:让非你控制的已存在的对象匹配特殊的接口
解决方案:Adapter提供了有着你想要的接口的包装
结果:Adapter模式允许已存在的对象适应新的类结构而不用受限于它们的原有接口
实现方法:在有着符合接口的另一个类中包含已存在的类,并调用它的方法

两种实现方式:
基于对象:让一个对象包含另一个对象
基于类:使用多继承类

Facade和Adapter的不同点:
Facade简化接口,而Adapter改变已存在的接口。

design pattern - adapter

  • 2014年03月27日 06:13
  • 31.8MB
  • 下载

Design Pattern--Adapter

1.Simple Adapter /**  *  */ package com.sean.adapter.simple; import java.awt.event.WindowEvent...
  • zfk
  • zfk
  • 2012年02月29日 17:19
  • 160

Design Pattern Explained 读书笔记四——Adapter

What?Convert the interface of a class into another interface that the clients expect. Adapter lets ...
  • lemon89
  • lemon89
  • 2015年07月28日 23:50
  • 459

Head First 设计模式 Design Pattern 7-8 Adapter & Facade, Template Method

Section 7 适配器模式和外观模式 Adapter & Facade >客户使用适配器 Client - Request -> Adapter -> TranslateRequest - A...

book-II (design pattern)

http://news.newhua.com/news1/program_language/2009/331/09331154241H4F5B57IF2530JJ43KC0D2GI396192EI3C...

Design Pattern: Adapter 模式 - Class Adapter

学习是分享和合作式的! 转载请注明出处:http://blog.csdn.net/wdzxl198/article/details/9223275; 文章摘自: http://www.riabook...

Design Pattern: Adapter 模式 - Object Adapter

学习是分享和合作式的! 转载请注明出处:http://blog.csdn.net/wdzxl198/article/details/9223275; 文章摘自: http://www.riabook...

Design Pattern学习笔记之适配和外观(the Adapter and Facade Pattern)

Design Pattern学习笔记之适配和外观(the Adapter and Facade Pattern) 1.    引子--Whois? a.      应用适配器模式可实现你想不到的伟...

Design Pattern - Structural Patterns - Adapter Pattern

2007 Section 1, Chapter 4 Adapter Pattern Concept It creates an adaptation between t...

系统集成之设计模式(Design Pattern)小结

  Singleton 定义:    一个类仅有一个通过私有全局变量去创建的实例。适用性: 1)客户端必须通过一个公用的端口获得仅存在的一个实例,例如一个局域网打印机系统,              ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Design pattern learning II: Adapter pattern
举报原因:
原因补充:

(最多只允许输入30个字)