September 2016
Intermediate to advanced
775 pages
18h 22m
English
To demonstrate the Proxy pattern, we will implement a simple protection proxy to view and add users. The service provides two options:
The SensitiveInfo class contains the information that we want to protect. The users variable is the list of existing users. The read() method prints the list of the users. The add() method adds a new user to the list. Let's consider the following code:
class SensitiveInfo: def __init__(self): self.users = ['nick', 'tom', 'ben', 'mike'] def read(self): print('There are {} users: {}'.format(len(self.users), ' '.join(self.users))) def add(self, ...