Php design mode-proxy mode

Source: Internet
Author: User
Php design pattern-Proxy pattern definition

Provides a proxy for other objects to control access to this object. In some cases, an object is not suitable or cannot directly reference another object, and the proxy object can play a mediation role between the client and the target object.

Primary role

Abstract roles: business methods implemented by declaring real roles through interfaces or abstract classes.

Proxy role: implements the abstract role, which is the proxy of a real role. you can use the business logic method of the real role to implement the abstract method and attach your own operations.

Real Role: implements abstract roles and defines the business logic to be implemented by real roles for proxy roles to call.

Advantages

Clear responsibilities

The proxy object can act as an intermediary between the client and the target object, which plays the role of intermediary and protects the target object.

High Scalability

Proxy mode instance

 GirlName = $ name;} function giveRose () {echo "{$ this-> girlName}: Your Rose
";} Function giveChocolate () {echo" {$ this-> girlName}: chocolate for you
";}} // Proxy role class Proxy implements IGiveGift {private $ follower; function _ construct ($ name = 'Girl ') {$ this-> follower = new Follower ($ name);} function giveRose () {$ this-> follower-> giveRose ();} function giveChocolate () {$ this-> follower-> giveChocolate () ;}$ proxy = new Proxy ('XXX'); $ proxy-> giveRose (); $ proxy-> giveChocolate ();

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.