LLD - Behavioral Design Patterns — Part 2
Given the following Python-like pseudocode for an Interpreter pattern, what will be the output?
class TerminalExpression:
def __init__(self, data):
self.data = data
def interpret(self, context):
return self.data in context
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)
expr1 = TerminalExpression('apple')
expr2 = TerminalExpression('banana')
and_expr = AndExpression(expr1, expr2)
print(and_expr.interpret(['apple', 'banana', 'cherry']))