php设计模式 Adapter(适配器模式)
2011-06-26 11:25
886 查看
<?php /** * 适配器模式 * * 将一个类的接口转换成客户希望的另外一个接口,使用原本不兼容的而不能在一起工作的那些类可以在一起工作 */ // 这个是原有的类型 class OldCache { public function __construct() { echo "OldCache construct<br/>"; } public function store($key,$value) { echo "OldCache store<br/>"; } public function remove($key) { echo "OldCache remove<br/>"; } public function fetch($key) { echo "OldCache fetch<br/>"; } } interface Cacheable { public function set($key,$value); public function get($key); public function del($key); } class OldCacheAdapter implements Cacheable { private $_cache = null; public function __construct() { $this->_cache = new OldCache(); } public function set($key,$value) { return $this->_cache->store($key,$value); } public function get($key) { return $this->_cache->fetch($key); } public function del($key) { return $this->_cache->remove($key); } } $objCache = new OldCacheAdapter(); $objCache->set("test",1); $objCache->get("test"); $objCache->del("test",1);
相关文章推荐
- [php]php设计模式 Adapter(适配器模式)
- Php设计模式之【适配器模式 Adapter Pattern】
- php设计模式 Adapter(适配器模式)
- PHP设计模式——适配器模式(Adapter)
- .NET设计模式-适配器模式(Adapter Pattern)
- 设计模式拾荒之适配器模式(Adapter Pattern)
- php设计模式之适配器模式
- Android设计模式--适配器模式--Adapter入门
- 我所理解的设计模式(C++实现)——适配器模式(Adapter Pattern)
- 我所理解的设计模式(C++实现)——适配器模式(Adapter Pattern)
- 深入浅出设计模式——适配器模式(Adapter Pattern)
- C#设计模式系列:适配器模式(Adapter)
- 设计模式(七)The Adapter and Facade Pattern 适配器模式与外观模式
- 我所理解的设计模式(C++实现)——适配器模式(Adapter Pattern)
- .NET设计模式(8):适配器模式(Adapter Pattern)
- 23种设计模式之适配器模式(Adapter)
- Java设计模式之适配器模式(Adapter)
- PHP设计模式系列(十二):适配器模式
- 设计模式--学习笔记--适配器模式Adapter--基础篇
- 设计模式学习笔记十一:适配器模式(Adapter Pattern)