php設(shè)計(jì)模式 Bridge (橋接模式)
更新時(shí)間:2011年06月26日 10:43:27 作者:
將抽象部份與它實(shí)現(xiàn)部分分離,使用它們都可以有獨(dú)立的變化
復(fù)制代碼 代碼如下:
<?php
/**
* 橋接模式
*
* 將抽象部份與它實(shí)現(xiàn)部分分離,使用它們都可以有獨(dú)立的變化
*/
abstract class Implementor
{
abstract public function operation();
}
class ConcreteImplementorA extends Implementor
{
public function operation()
{
echo "ConcreteImplementorA Operation<br/>";
}
}
class ConcreteImplementorB extends Implementor
{
public function operation()
{
echo "ConcreteImplementorB Operation<br/>";
}
}
class Abstraction
{
protected $_implementor = null;
public function setImplementor($implementor)
{
$this->_implementor = $implementor;
}
public function operation()
{
$this->_implementor->operation();
}
}
class RefinedAbstraction extends Abstraction
{
}
class ExampleAbstraction extends Abstraction
{
}
//
$objRAbstraction = new RefinedAbstraction();
$objRAbstraction->setImplementor(new ConcreteImplementorB());
$objRAbstraction->operation();
$objRAbstraction->setImplementor(new ConcreteImplementorA());
$objRAbstraction->operation();
$objEAbstraction = new ExampleAbstraction();
$objEAbstraction->setImplementor(new ConcreteImplementorB());
$objEAbstraction->operation();
相關(guān)文章
apache+codeigniter 通過(guò).htcaccess做動(dòng)態(tài)二級(jí)域名解析
今天將服務(wù)器php版本升到了5.4.4,然后將之前的一個(gè)項(xiàng)目改用apache,動(dòng)態(tài)二級(jí)轉(zhuǎn)向用.htcaccess實(shí)現(xiàn)了動(dòng)態(tài)二級(jí)域名解析,共享一下2012-07-07
php基礎(chǔ)知識(shí):類(lèi)與對(duì)象(5) static
php基礎(chǔ)知識(shí):類(lèi)與對(duì)象(5) static...2006-12-12
解決file_get_contents無(wú)法請(qǐng)求https連接的方法
PHP.ini默認(rèn)配置下,用file_get_contents讀取https的鏈接,就會(huì)報(bào)如下錯(cuò)誤,本文給出解決方法2013-12-12
淺談PHP 閉包特性在實(shí)際應(yīng)用中的問(wèn)題
PHP5.3 新版本跟隨了很多新特性, 其中比較惹眼的特性之一就是支持了閉包。那么以后,我們也可以和那幫寫(xiě) Ruby、Javascript 等等“高科技語(yǔ)言”的家伙們一樣,寫(xiě)出非常酷的代碼嗎?2009-10-10

