php设计模式 Adapter(适配器模式)
2015-01-24信息快讯网
将一个类的接口转换成客户希望的另外一个接口,使用原本不兼容的而不能在一起工作的那些类可以在一起工作
<?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);
Could not load type System.ServiceModel.Activation.HttpModule解决办法
PHP类与对象中的private访问控制的疑问
php类中private属性继承问题分析
PHP5下$_SERVER变量不再受magic_quotes_gpc保护的弥补方法
php获取ip的三个属性区别介绍(HTTP_X_FORWARDED_FOR,HTTP_VIA,REMOTE_ADDR)
巧用php中的array_filter()函数去掉多维空值的代码分享
PhpMyAdmin出现export.php Missing parameter: what /export_type错误解决方法
UCenter 批量添加用户的php代码
apache+codeigniter 通过.htcaccess做动态二级域名解析
深入了解 register_globals (附register_globals=off 网站打不开的解决方法)
php开启安全模式后禁用的函数集合
php设计模式 Builder(建造者模式)
php设计模式 Interpreter(解释器模式)
php设计模式 Strategy(策略模式)
php设计模式 Template (模板模式)
php设计模式 Composite (组合模式)
php设计模式 State (状态模式)
PHP数组的交集array_intersect(),array_intersect_assoc(),array_inter_key()函数的小问题
php将fileterms函数返回的结果变成可读的形式
php expects parameter 1 to be resource, array given 错误
php iconv() : Detected an illegal character in input string