複製程式碼程式碼如下:
/**
* 中介者模式
*
* 用一個中介對象來封裝一系列的對象交互,使各對像不需要顯式地相互引用從而使其耦合鬆散,而且可以獨立地改變它們之間的互動
*/
抽象類Mediator
/***/
抽象類Mediator
/***/
抽象類別Mediator
{
抽象公共函數send($message,$colleague);
}
抽象類別Colleague
{
private $_mediator = null;
public function Collatague($mediator )
{
$this->_mediator = $mediator;
}
公用函數send($message)
{
$this->_mediator->send($message, $this);
}
抽象公用函數notify($message);
}
class ConcreteMediator 擴充了Mediator
{
private $_colleague1 = null;
{
private $_colleague1 = null;
私人; _colleague2 = null;
public function send($message,$colleague)
{
if($colleague == $this->_colleague1)
{
$this->_colleague1-> notify ($訊息);
} else {
$this->_colleague2->notify($message);
}
}
公用函數集($colleague1,$colleague2)
{
$this->_colleague1 = $colleague1;
$this->_colleague2 = $colleague2;
}
}
class Colleague1 擴充了league
}
class Colleague1 擴充了league
public function notify($message)
{
echo "Colleague1 訊息是:".$message."”;
}
}
class Colleague2 擴充了Colleague
{
public function notification($message)
{
echo "Colleague2 訊息是:".$message."」;
}
}
//
$objC1 = new Colleague1($objMediator);
$objC2 = new Colleague2($objMediator);$objC2 = new Colleague2($objMediator);
$objC2 = new Colleague2($objMediator); $objMator>$ob objC2); $objC1->send("從c1 到c2"); $objC2->send("從c2 到c1"); 以上就介紹了com.cooliris.media php設計模式Mediator內者模式,包含了com.cooliris.media方面的內容,希望對PHP教學有興趣的朋友有幫助。