<?php /** * @Description: 职责链模式 * @Author: luoxiaojin * @Date: 2020-06-29 16:20:03 * @LastEditors: luoxiaojin * @LastEditTime: 2020-06-30 10:09:38 * @FilePath: \design_patterns\l6.php */ // 解决举报问题 class Board{ public $power = 30; protected $top = 'Admin'; public function process($level){ if($level>$this->power){ (new $this->top())->process($level); }else{ echo "Board处理完成!"; } } } class Admin{ public $power = 60; protected $top = 'Police'; public function process($level){ if($level>$this->power){ (new $this->top())->process($level); }else{ echo "Admin处理完成!"; } } } class Police{ public function process($level){ echo "Police处理完成"; } } $b = new Board(); $b->process(rand(0,90));
点击 "运行实例" 按钮查看在线实例
——学习参考与 bilibili燕十八 面向对象与设计模式