码迷,mamicode.com
首页 > Web开发 > 详细

php设计模式之责任链模式

时间:2017-12-26 14:28:03      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:prot   function   ==   roc   bsp   nbsp   extends   责任链模式   int   

<?php
class Admin {
public function __construct() {
if($this->top === null) {
return;
}
$this->toper = new $this->top();
}

public function proc($danger) {
if($danger <= $this->power) {
$this->doProc();
} else {
$this->toper->proc($danger);
}
}
}

class Banzhu extends Admin {
protected $power = 1;
protected $top = ‘Police‘;


protected function doProc() {
echo ‘删帖‘;
}
}

class Police extends Admin {
protected $power = 2;
protected $top = ‘Guoan‘;

public function doProc() {
echo ‘抓人‘;
}
}

class Guoan extends Admin {
protected $power = 3;
protected $top = null;

public function doProc() {
echo ‘灭口‘;
}
}

 

$danger = 3;

$admin = new Banzhu();
$admin->proc($danger);
echo "<pre>";
print_r($admin);

php设计模式之责任链模式

标签:prot   function   ==   roc   bsp   nbsp   extends   责任链模式   int   

原文地址:https://www.cnblogs.com/aiit/p/8117339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!