php設計模式 Bridge (橋接模式)
更新時間:2011年06月26日 10:43:27 作者:
將抽象部份與它實現(xiàn)部分分離,使用它們都可以有獨立的變化
復制代碼 代碼如下:
<?php
/**
* 橋接模式
*
* 將抽象部份與它實現(xiàn)部分分離,使用它們都可以有獨立的變化
*/
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();
相關文章
apache+codeigniter 通過.htcaccess做動態(tài)二級域名解析
今天將服務器php版本升到了5.4.4,然后將之前的一個項目改用apache,動態(tài)二級轉向用.htcaccess實現(xiàn)了動態(tài)二級域名解析,共享一下2012-07-07
解決file_get_contents無法請求https連接的方法
PHP.ini默認配置下,用file_get_contents讀取https的鏈接,就會報如下錯誤,本文給出解決方法2013-12-12

