SOCKS Hot Knowledge Share: What is a Static proxy?

TabProxy

Newbie
Joined
3 Apr 2024
Messages
28
Reaction score
0
Points
1
Click to see Surprise Proxies

A static proxy is a design pattern that allows new functionality or behaviour to be added to a target object without modifying it. A static proxy class is determined at compile time and implements the same interface as the target object or inherits from the same parent class. When a client requests the target object, it is intercepted and processed by the proxy object, which can enhance or filter the request before forwarding it to the target object.

Advantages of static proxy.
1, no need to modify the target object code
2, easy to understand and implement
3, you can add a variety of functions for the target object

Disadvantages of static proxy.
1, the proxy class is tightly coupled with the target object, if the target object interface changes, the proxy class also needs to be modified
2, may lead to code redundancy, because the proxy class needs to repeat the implementation of the target object's methods

Static proxy application scenarios.
1, in the case of the target object code is difficult to modify, add new functions or behaviours for it
2, for the target object to add security checks or logging functions
3, the implementation of caching or load balancing and other functions