国产探花免费观看_亚洲丰满少妇自慰呻吟_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);

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 靖江市| 贺州市| 富锦市| 西畴县| 乌拉特前旗| 东山县| 沂源县| 安庆市| 廊坊市| 神农架林区| 苏尼特右旗| 深圳市| 土默特左旗| 都昌县| 宣城市| 齐齐哈尔市| 紫云| 德州市| 永和县| 东乡族自治县| 临西县| 邹城市| 长治县| 鹿邑县| 庆城县| 皮山县| 华池县| 博罗县| 蓝田县| 白朗县| 疏勒县| 淮滨县| 上虞市| 马公市| 休宁县| 芦溪县| 巴东县| 易门县| 松江区| 德州市| 常州市|