php設(shè)計模式 Adapter(適配器模式)
更新時間:2011年06月26日 11:25:28 作者:
將一個類的接口轉(zhuǎn)換成客戶希望的另外一個接口,使用原本不兼容的而不能在一起工作的那些類可以在一起工作
復(fù)制代碼 代碼如下:
<?php
/**
* 適配器模式
*
* 將一個類的接口轉(zhuǎn)換成客戶希望的另外一個接口,使用原本不兼容的而不能在一起工作的那些類可以在一起工作
*/
// 這個是原有的類型
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設(shè)計模式之適配器模式(Adapter)原理與用法詳解
- PHP設(shè)計模式之適配器模式代碼實例
- 學(xué)習(xí)php設(shè)計模式 php實現(xiàn)適配器模式
- PHP設(shè)計模式之適配器模式原理與用法分析
- php設(shè)計模式之適配器模式原理、用法及注意事項詳解
- PHP設(shè)計模式之適配器模式定義與用法詳解
- php設(shè)計模式之適配器模式實例分析【星際爭霸游戲案例】
- PHP設(shè)計模式(四)原型模式Prototype實例詳解【創(chuàng)建型】
- PHP設(shè)計模式(三)建造者模式Builder實例詳解【創(chuàng)建型】
- PHP設(shè)計模式(一)工廠模式Factory實例詳解【創(chuàng)建型】
- PHP設(shè)計模式概論【概念、分類、原則等】
- PHP設(shè)計模式(五)適配器模式Adapter實例詳解【結(jié)構(gòu)型】
相關(guān)文章
php+mysql開發(fā)中的經(jīng)驗與常識小結(jié)
這篇文章主要介紹了php+mysql開發(fā)中的經(jīng)驗與常識,簡單總結(jié)分析了php+mysql數(shù)據(jù)庫程序設(shè)計中的命名規(guī)范、數(shù)據(jù)庫表、字段、索引等相關(guān)設(shè)計與使用規(guī)范,需要的朋友可以參考下2019-03-03
php使用imagecopymerge()函數(shù)創(chuàng)建半透明水印
這篇文章主要介紹了php使用imagecopymerge()函數(shù)創(chuàng)建半透明水印,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01
php使用ftp遠程上傳文件類(完美解決主從文件同步問題的方法)
下面小編就為大家?guī)硪黄猵hp使用ftp遠程上傳文件類(完美解決主從文件同步問題的方法)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-09-09

