MCPcopy Create free account
hub / github.com/RefactoringGuru/design-patterns-python / request

Method request

src/Proxy/Conceptual/main.py:63–79  ·  view source on GitHub ↗

EN: The most common applications of the Proxy pattern are lazy loading, caching, controlling the access, logging, etc. A Proxy can perform one of these things and then, depending on the result, pass the execution to the same method in a linked RealSubject object.

(self)

Source from the content-addressed store, hash-verified

61 self._real_subject = real_subject
62
63 def request(self) -> None:
64 """
65 EN: The most common applications of the Proxy pattern are lazy loading,
66 caching, controlling the access, logging, etc. A Proxy can perform one
67 of these things and then, depending on the result, pass the execution to
68 the same method in a linked RealSubject object.
69
70 RU: Наиболее распространёнными областями применения паттерна Заместитель
71 являются ленивая загрузка, кэширование, контроль доступа, ведение
72 журнала и т.д. Заместитель может выполнить одну из этих задач, а затем,
73 в зависимости от результата, передать выполнение одноимённому методу в
74 связанном объекте класса Реального Субъекта.
75 """
76
77 if self.check_access():
78 self._real_subject.request()
79 self.log_access()
80
81 def check_access(self) -> bool:
82 print("Proxy: Checking access prior to firing a real request.")

Callers 1

client_codeFunction · 0.45

Calls 2

check_accessMethod · 0.95
log_accessMethod · 0.95

Tested by

no test coverage detected