When using an existing method, you need to improve or modify the original method. At this time, there are two ways to improve: modify the original method to adapt to the current use method, or use a "third party" method to call the original method, and control the results of the method. The first method obviously violates the principle of "open to extension and disable to modify", and modifications to the original method may blur and diversify the functions of the original class, the second method can be used to clearly classify functions and facilitate subsequent maintenance. So to some extent, the second method is a good choice! This is the proxy mode.
Proxy can be divided by purpose.
Remote Proxy: provides a Local Area Representative object for an object in a different address space. The address space can be in this machine or another machine. Remote proxy is also called ambassador ).
Virtual Proxy: creates an object with high resource consumption as needed, so that the object is created only when necessary.
Copy-on-write Proxy: a virtual proxy. Delays replication (cloning) until the client needs it.
Protection (protect or access) proxy: controls access to an object. If necessary, different users can be granted different levels of access permissions.
Cache Proxy: provides a temporary storage space for the results of a target operation so that multiple clients can share the results.
Firewall Proxy: protects the target from malicious users.
Synchronization Proxy: enables several users to simultaneously use an object without conflict.
Smart reference Proxy: provides some additional operations when an object is referenced, such as recording the number of calls to this object.
In all types of proxy modes, virtual proxy, remote proxy, smart reference proxy, and protect or access) proxy is the most common proxy mode.