LLD - Behavioral Design Patterns — Part 2
Consider this simplified Python code using the Memento pattern:
What will be printed?
class Memento:
def __init__(self, state):
self._state = state
class Originator:
def __init__(self):
self._state = ""
def set_state(self, state):
self._state = state
def save(self):
return Memento(self._state)
def restore(self, memento):
self._state = memento._state
originator = Originator()
originator.set_state("State1")
memento = originator.save()
originator.set_state("State2")
originator.restore(memento)
print(originator._state)What will be printed?
