PHP门面设计模式
";
}
function sell()
{
echo "卖出阿里股票
"; } } /**万达股票 * Class Wanda */ class Wanda { function buy() { echo "买入万达股票
"; } function sell() { echo "卖出万达股票
"; } } /**京东股票 * Class Jingdong */ class Jingdong { function buy() { echo "买入京东股票
"; } function sell() { echo "卖出京东股票
"; } } /**门面模式核心角色 * Class FacadeCompany */ class FacadeCompany { private $ali; private $wanda; private $jingdong; function __construct() { $this->ali=new Ali(); $this->jingdong=new Jingdong(); $this->wanda=new Wanda(); } function buy() { $this->wanda->buy(); $this->ali->buy(); } function sell() { $this->jingdong->sell(); } } 客户端调用代码: [php] view plain copy print? header("Content-Type:text/html;charset=utf-8"); //------------------------门面模式测试代码------------------ require_once "./Facade/Facade.php"; $lurenA=new FacadeCompany(); $lurenA->buy(); $lurenA->sell(); 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 更多技术文章请搜索千锋PHP,做真实的自己,用良心做教育。 互联网+时代,时刻要保持学习,携手千锋PHP,Dream It Possible。
"; } } /**万达股票 * Class Wanda */ class Wanda { function buy() { echo "买入万达股票
"; } function sell() { echo "卖出万达股票
"; } } /**京东股票 * Class Jingdong */ class Jingdong { function buy() { echo "买入京东股票
"; } function sell() { echo "卖出京东股票
"; } } /**门面模式核心角色 * Class FacadeCompany */ class FacadeCompany { private $ali; private $wanda; private $jingdong; function __construct() { $this->ali=new Ali(); $this->jingdong=new Jingdong(); $this->wanda=new Wanda(); } function buy() { $this->wanda->buy(); $this->ali->buy(); } function sell() { $this->jingdong->sell(); } } 客户端调用代码: [php] view plain copy print? header("Content-Type:text/html;charset=utf-8"); //------------------------门面模式测试代码------------------ require_once "./Facade/Facade.php"; $lurenA=new FacadeCompany(); $lurenA->buy(); $lurenA->sell(); 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 更多技术文章请搜索千锋PHP,做真实的自己,用良心做教育。 互联网+时代,时刻要保持学习,携手千锋PHP,Dream It Possible。

浙公网安备 33010602011771号