php中介模式,PHP-设计模式之-中介者模式

//中介者模式 --

//抽象中介者

abstract class UnitedNationa{

punlic abstract function Declared($message,country $colleague)

}

class UnitedCommit extends UnitedNationa{

punlic $countryUsa;

punlic $countryChina;

punlic function Declared($message,Country $colleague){

if ($colleague == $this->countryChina) {

$this->countryUsa->GetMessage()

} else {

$this->countryChina->GetMessage()

}

}

}

//抽象国家

abstract class Country{

protected $mediator;

public function construct(UnitedNations $_mediator){

$this->mediator = $_mediator

}

}

//具体国家类

class USA extends Country {

function __construct(UnitedNations $mediator){

parent::__construct($mediator);

}

//声明

public function Declared($mediator){

$this->mediator->Declared($message,$this);

}

//获得消息

public function GetMessage($message){

echo "获得消息:$message
";

}

}

class china extends Country{

public function __construct(UnitedNations,$mediator){

parent::__construct($mesiator);

}

//声明

public function Declared($message){

$this->declared($message,$this);

}

//获取消息

public function GetMessage($message){

echo "得到消息:$message
";

}

}

$zj = new UnitedCommit();

$c1 = new USA($zj);

$c2 = new China($zj);

$zj->countryChina = $c2

$zj->countryUSA = $c1

$c1->Declared('12');

$c2->Declared('23');

标签:function,Declared,PHP,mediator,中介,construct,message,设计模式,public

来源: https://www.cnblogs.com/songyanan/p/10626738.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值