객체의 상태를 사진처럼 메멘토로 저장해서 원할 때 그 상태로 되돌리는 패턴
import uuid
from datetime import datetime
class CatMemento:
def __init__(self,age,height):
self.uuid = uuid.uuid4()
self.created_time = datetime.now()
self.age = age
self.height = height
class Cat:
def __init__(self,age,height):
self.age = age
self.height = height
def speak(self):
print(f'{self.age}year old, {self.height}cm, meow')
def createMemento(self):
cat_memento = CatMemento(self.age,self.height)
return cat_memento
def restore(self,memento):
self.age = memento.age
self.height = memento.height