美文网首页
业务代表模式

业务代表模式

作者: 散装咖啡 | 来源:发表于2017-05-30 02:46 被阅读62次
//businessDelegate
interface BusinessService
{
    public function doProcessing();
}

class EJBService implements BusinessService
{
    public function doProcessing()
    {
        echo 'Processing task by invoking EJB Service' . "<br />";
    }
}


class JMSService implements BusinessService
{
    public function doProcessing()
    {
        echo 'Processing task by invoking JMS Service'. "<br />";
    }
}

class BusinessLookUp
{
    public function getBusinessService($serviceType)
    {
        //返回0就是相等
        if (!strcasecmp('EJB', $serviceType)) {
            return new EJBService();
        } else {
            return new JMSService();
        }
    }
}

class BusinessDelegate
{
    private $lookupService = null;
    private $businessService = null;
    private $serviceType = null;
    
    public function __construct()
    {
        $this->lookupService = new BusinessLookUp;
    }
    
    public function setServiceType($serviceType)
    {
        $this->serviceType = $serviceType;
    }
    
    public function doTask()
    {
        $this->businessService = $this->lookupService->getBusinessService($this->serviceType);
        $this->businessService->doProcessing();
    }
}

class Client
{
    public $businessService = null;
    
    public function Client($businessService)
    {
        $this->businessService = $businessService;
    }
    
    public function doTask()
    {
        $this->businessService->doTask();
    }
}


$BusinessDelegate = new BusinessDelegate();
$BusinessDelegate->setServiceType("EJB");

$Client = new Client($BusinessDelegate);
$Client->doTask();

$BusinessDelegate->setServiceType("JMS");
$Client->doTask();

参考文章 http://www.runoob.com/design-pattern/business-delegate-pattern.html

相关文章

  • 业务代表模式

    参考文章 http://www.runoob.com/design-pattern/business-delega...

  • 业务代表模式

    前言: 因为现在设计模式在网络上已经泛滥,但是还是有好多程序员不能够灵活的运用设计模式,这个是对设计模式简单的介绍...

  • Java业务代表模式

  • 设计模式之业务代表模式

    简介 业务代表模式(Business Delegate Pattern)用于对表示层和业务层解耦。它基本上是用来减...

  • 设计模式|菜鸟教程 - C5 J2EE 模式

    --书写中--- 0 Intro MVC 模式(MVC Pattern)业务代表模式(Business Deleg...

  • 第二式 业务代表模式

    1.简介 业务代表模式用于对表示层和业务层解耦。它基本上是用来减少通信或对表示层代码中的业务层代码的远程查询功能。...

  • 架构衍生工具——业务模式画布

    业务模式画布 一、概述 业务模式画布(亦称为业务模式九要素)是一种用来描述业务模式、可视化业务模式、评估业务模式以...

  • 业务代表加入

    第一️@首先准备好4个内容: 1,身份证正、反面; 2,手持身份证拍照(不能戴眼镜,照片要清晰,不能美颜); 3,...

  • Android 中MVP模式入门

    1、MVP和MVC MVC简介 在Android我们经常会用MVC模式,其中。 M对应Model,代表业务数据V对...

  • Django-02-视图和模板

    首先,先简单理解下django的MTV模式。 M 代表模型(Model):负责业务对象和数据库的关系映射(ORM)...

网友评论

      本文标题:业务代表模式

      本文链接:https://www.haomeiwen.com/subject/flglfxtx.html