Bridge to Control and Flexibility
In a nutshell, the proxy Design Pattern acts as a versatile bridge between clients and real objects, offering control, flexibility, and enhanced functionality in your software architecture.
class RealSubject:
def request(self):
print("RealSubject: Handling request.")
class Proxy:
def __init__(self):
self._real_subject = None
def request(self):
if self._real_subject is None:
self._real_subject = RealSubject()
print("Proxy: Pre-processing request.")
self._real_subject.request()
print("Proxy: Post-processing request.")
# Client code
proxy = Proxy()
proxy.request() # Output:
# Proxy: Pre-processing request.
# RealSubject: Handling request.
# Proxy: Post-processing request.