适配器模式Adapter

1. 转换匹配, 复用功能:

原来是文件类的读写接口read, write,新的方式是数据库的add ,update,insert, delete接口。

现在要用新的数据库方式,但同时保存原来的文件读写。

解决方法:
适配器模式Adapter

适配器模式Adapter
外面看上去是新接口,里面调用和实现的却是旧接口。
适配器模式Adapter
适配器模式Adapter
2. 双向适配器

  • 在db的add,remove,update,get的接口里面用file的方式实现
  • 在file的read,write接口里面用db的方式实现

3. 对象适配器、类适配器又略有差别。