Blogger Information
Blog 11
fans 0
comment 0
visits 6626
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP设计模式学习笔记——职责链模式
青Blue的博客
Original
620 people have browsed it

实例

<?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燕十八 面向对象与设计模式

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post