复制代码 代码如下:
<?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);
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!