<?php/* Proxy mode proxy mode is a structured pattern that provides a proxy for other objects to control access to this object. For example, Wu Zetian provided an agent for Lizhi to administer the country (object)//role? Abstract theme Role (Subject): It functions as a unified interface. This role defines the interfaces that are common to both real-world and agent-themed roles, so that you can use the proxy theme role where you use real-world theme roles. Real theme Role (Realsubject): A real object hidden behind a proxy role. (Lizhi)? Agent-themed role (proxysubject): It acts as a proxy for real topics and retains references to real-world roles within it. It inherits from the abstract theme roles and maintains the unity of the interface with the real theme characters. It controls access to real-world topics and may be responsible for creating and deleting real objects. The proxy role is not a simple forwarding, and typically you can simply forward a call before or after it is passed to the real object. Compared to adapter mode: The adapter mode is to change the interface of the object, and the proxy mode does not change the interface of the Proxied object. *//* Abstract interface One of the biggest reasons is to constrain the behavior of both sides! What do you mean? In fact, I forced the proxy must implement certain methods, and these methods are the main business method of public disclosure in this example is Lizhi constrained agent (Wu Zetian) can only kill can not do other */interface subject{public function killpeople ();} Lizhi class Realsubject implements Subject {//Real theme role Public function __construct () {} public Function killpeople () {echo ' kill grandson Mowgli ';}} Proxy mode can not change the interface of real character, only use; Class Proxysubject{private $subject = NULL;p ublic function __construct (realsubject $RealSubject) {$this->subject = $R Ealsubject;} Public Function Killpeople () {if (Is_null ($this->subject)) {$this->subject = $RealSubject;} $this->subject->killpeople ();}} CliENT Agent Wu Zetian $wuzetian = new Proxysubject (); $wuzetian->killpeople ();
design mode in PHP--proxy mode