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 ();