design-patterns/structural/proxy/main.py
Ruidy 18dc62563c
Proxy (#13)
* doc: add proxy README documentation

* doc: edit general README files

* add proxy code example

Co-authored-by: Ruidy <r.nemausat@empfohlen.de>
2020-09-29 21:08:07 +02:00

25 lines
885 B
Python

from structural.proxy.proxy import Proxy
from structural.proxy.real_subject import RealSubject
from structural.proxy.subject import Subject
def client_code(subject: Subject) -> None:
"""
The client code is supposed to work with all objects (both subjects and
proxies) via the Subject interface in order to support both real subjects
and proxies. In real life, however, clients mostly work with their real
subjects directly. In this case, to implement the pattern more easily, you
can extend your proxy from the real subject's class.
"""
subject.request()
if __name__ == '__main__':
print("Client: Executing the client code with a real subject:")
real_subject = RealSubject()
client_code(real_subject)
print('')
print("Client: Executing the same client code with a proxy:")
proxy = Proxy(real_subject)
client_code(proxy)