Middle
To which group does the Proxy pattern belong and what is it used for?
sobes.tech AI
Answer from AI
The Proxy pattern belongs to the group of structural design patterns. Its main purpose is to provide a surrogate object that controls access to another object, intercepting calls and adding additional behavior if necessary.
Used for:
- Lazy initialization
- Access control
- Caching results
- Logging calls
- Remote access to objects
Example in Python:
class RealSubject:
def request(self):
print("Executing request")
class Proxy:
def __init__(self):
self.real_subject = RealSubject()
def request(self):
print("Proxy: checking access before call")
self.real_subject.request()
print("Proxy: additional behavior after call")
proxy = Proxy()
proxy.request()