def __init__(self, payment_cls=PaymentProcessor, max_value=10, rules=None): self.__payment_processor = payment_cls() self.__max_value = max_value self.__rules = rules or [] def pay(self, amt): for r in rules: if not r[0](amt): raise r[1] if amt>self.__max_value: raise Error return self.__payment_processor.pay(amt) rules = [(lambda x: x<-‐1, "Price can't be negative"), (lambda x: x>100, "Price can't be more than 100)") a = PaymentProxy(rules=rules) a.pay(9) a = PaymentProxy(payment_cls=VisaProcessor, max_value=666) a.pay(100)