renamed package to pypattyrn

This commit is contained in:
tylerlaberge
2016-09-10 22:06:11 -04:00
parent bf8dd3830b
commit 3d5efea9b0
143 changed files with 16151 additions and 567 deletions

View File

@@ -0,0 +1,47 @@
from copy import deepcopy
class Memento(object):
"""
Memento class as part of the Memento design pattern.
- External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Behavioral-Pattern-Usage}
- External Memento Pattern documentation: U{https://en.wikipedia.org/wiki/Memento_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.
- External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Behavioral-Pattern-Usage}
- External Mediator Pattern documentation: U{https://en.wikipedia.org/wiki/Memento_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