Proxy Pattern, also known as Delegate Pattern, is a structural design Pattern. The frequency of Proxy Pattern is very high. AOP of Spring is a typical case.

The proxy pattern

define

  • Provide a proxy for other objects to control access to that object
  • A proxy object acts as a mediator and can remove or add additional functionality

Proxy schema UML class diagramProxy objects refer to the original RealSubject in a composite manner and implement the Subject interface Proxy pattern UML sequence diagramsThe client works by Proxy, which forwards requests to the base object (RealSubject). Before forwarding, the Proxy performs access control to control the access to the base object and extends new functions

  • Proxy implementations can be divided into static and dynamic proxies

advantages

  • Clear responsibilities to achieve the actual business logic, do not care about other non-charged transactions, through the late agent to complete the need to add functions
  • A proxy object can act as an intermediary between the client and the target object, thus acting as a mediator and protecting the target object
  • High scalability