首页 > Web开发 > 详细

php设计模式--门面模式

时间:2019-12-19 15:44:48      阅读:98      评论:0      收藏:0      [点我收藏+]

优势:松耦合,屏蔽组件。依赖分层

class ali 
{
    function buy(){
        echo "买入阿里<br/>";
    }

    function sell(){
        echo "卖出阿里<br>";
    }
}

class hds 
{
    function buy(){
        echo "买入x德森<br/>";
    }

    function sell(){
        echo "卖出汉xx<br>";
    }
}

class hfjy 
{
    function buy(){
        echo "买入xxx<br/>";
    }

    function sell(){
        echo "卖出xx教育<br>";
    }
}

class menmian
{

    private $ali;
    private $hfjy;
    private $hds;

    function __construct(){
        $this->ali = new ali();
        $this->hds = new hds();
        $this->hfjy = new hfjy();
    }
    public  function buy(){
        $this->ali->buy();
    }
    public  function sell(){
        $this->hfjy->sell();
        $this->hds->sell();
    }
}

$res = new menmian();
$res->buy();
echo "<hr>";
$res->sell();

php设计模式--门面模式

原文:https://www.cnblogs.com/songyanan/p/12067813.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!