手机
当前位置:查字典教程网 >编程开发 >php教程 >php设计模式 Adapter(适配器模式)
php设计模式 Adapter(适配器模式)
摘要:复制代码代码如下:

复制代码 代码如下:

<?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设计模式 Adapter(适配器模式)】相关文章:

用PHP4访问Oracle815

PHP脚本监控Nginx 502错误并自动重启php-fpm

域名查询代码公布

PHP设计模式之适配器模式代码实例

建立文件交换功能的脚本(三)

PHP设计模式之装饰者模式代码实例

php跨服务器访问方法小结

Windows下的PHP5.0安装配制详解

php页面缓存ob系列函数介绍

PHP安全配置

精品推荐
分类导航