Proxy Pattern

In proxy pattern, a class represents functionality of another class. This type of design pattern comes under structural pattern.

In proxy pattern, we create object having original object to interface its functionality to outer world.

import abc
class Greeter(abc.ABC):
@abc.abstractmethod
def greet(self):
pass

class RealGreeter(Greeter):
def __init__(self, name):
self.name = name
def greet(self):
return str("Hello " + self.name)

class GreaterProxy(Greeter):
greeter = None
def greet(cls, name):
# Check if the user is authorized before calling real greater
# Check real greater is available ( resources )

if cls.greeter == None:
cls.greeter = RealGreeter(name)
else:
cls.greeter.name = name
return cls.greeter.greet()

proxy = GreaterProxy()
print(proxy.greet("Chang"))