moved memento into behavioural directory

This commit is contained in:
tylerlaberge
2016-08-20 17:12:32 -04:00
parent 92c34c5f88
commit 392ea5d02e
2 changed files with 2 additions and 1 deletions
+41
View File
@@ -0,0 +1,41 @@
from copy import deepcopy
class Memento(object):
"""
Memento class as part of the Memento design pattern.
"""
def __init__(self, state):
"""
Initialize a new Memento instance.
@param state: The state to save in this Memento.
@type state: dict
"""
self.__state = state
@property
def state(self):
return self.__state
class Originator(object):
"""
Originator base class as part of the Memento design pattern.
"""
def commit(self):
"""
Commit this objects state to a memento.
@return: A memento instance with this objects state.
"""
return Memento(deepcopy(self.__dict__))
def rollback(self, memento):
"""
Rollback this objects state to a previous state.
@param memento: The memento object holding the state to rollback to.
@type memento: Memento
"""
self.__dict__ = memento.state