LLD - Behavioral Design Patterns — Part 2
What will be the output of this code snippet using the Interpreter pattern?
class AndExpression:
def __init__(self, expr1, expr2):
self.expr1 = expr1
self.expr2 = expr2
def interpret(self, context):
return self.expr1.interpret(context) and self.expr2.interpret(context)
class TerminalExpression:
def __init__(self, data):
self.data = data
def interpret(self, context):
return self.data == context
expr = AndExpression(TerminalExpression('A'), TerminalExpression('B'))
print(expr.interpret('A'))