<?php /** **代理模式Proxy: *********/ abstract class Person{ abstract public function action(); } class RealPerson extends Person{ public function action(){ echo ‘RealPerson‘; } } class ProxyPerson extends Person{ private $_realsubject = NULL; public function __construct(){ } public function action(){ $this->_beforeAction(); if(is_null($_realsubject)){ $this->_realsubject = new RealPerson(); $this->_realsubject->action(); } $this->_afterAction(); } public function _beforeAction(){ echo ‘beforeAction‘; } public function _afterAction(){ echo ‘afterAction‘; } }
class Client{ public static function test(){ $request = new ProxyPerson(); $request->action(); } } Client::test();
时间: 2024-10-05 13:47:32