design mode in PHP--proxy mode

Source: Internet
Author: User

<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.