设计模式六:代理模式

代理模式:

  给对象提供一个代理类,由代理对象对外接洽。

<?php

interface A {
    public function boot();
}

class B implements A{
    public function boot(){
        echo '此处是B类';
    }
}

/**
 * 代理类
 */
class Proxy implements A{
    
    private $b;

    public function __construct(A $b)
    {
        $this->b = $b;
    }

    //此处执行的是代理的类方法
    public function boot()
    {
        return $this->b->boot();    
    }
}

$proxy = new Proxy(new B());
$proxy->boot();

posted @ 2021-08-24 15:11  wish_yang  阅读(23)  评论(0编辑  收藏  举报