复制代码 代码如下:
zuojiankuohaophpcn?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怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号