业务代表模式

//businessDelegate
interface BusinessService
{
    public function doProcessing();
}

class EJBService implements BusinessService
{
    public function doProcessing()
    {
        echo 'Processing task by invoking EJB Service' . "
"; } } class JMSService implements BusinessService { public function doProcessing() { echo 'Processing task by invoking JMS Service'. "
"; } } 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

你可能感兴趣的:(业务代表模式)