亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php設(shè)計(jì)模式 Adapter(適配器模式)

 更新時(shí)間:2011年06月26日 11:25:28   作者:  
將一個(gè)類的接口轉(zhuǎn)換成客戶希望的另外一個(gè)接口,使用原本不兼容的而不能在一起工作的那些類可以在一起工作
復(fù)制代碼 代碼如下:

<?php
/**
* 適配器模式
*
* 將一個(gè)類的接口轉(zhuǎn)換成客戶希望的另外一個(gè)接口,使用原本不兼容的而不能在一起工作的那些類可以在一起工作
*/

// 這個(gè)是原有的類型
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);

相關(guān)文章

最新評論