国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php設計模式 Adapter(適配器模式)

2024-05-04 23:17:53
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:


<?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);

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 清流县| 舒兰市| 北票市| 沙洋县| 巴彦淖尔市| 永善县| 龙海市| 宝山区| 张家港市| 龙川县| 微博| 南平市| 博爱县| 错那县| 明水县| 平舆县| 望江县| 兴化市| 通榆县| 阜南县| 平武县| 达日县| 麟游县| 宾川县| 苍梧县| 修水县| 额尔古纳市| 金湖县| 岢岚县| 余庆县| 通榆县| 沧州市| 嵩明县| 固安县| 宝坻区| 平罗县| 阜阳市| 乐昌市| 昌都县| 方城县| 桃源县|