renamed package.

This commit is contained in:
tylerlaberge
2016-09-10 17:11:45 -04:00
parent 52ceb712d4
commit cee2bc400b
39 changed files with 23 additions and 23 deletions
+25
View File
@@ -0,0 +1,25 @@
from copy import deepcopy
from types import MethodType
class Prototype(object):
"""
Prototype design pattern abstract class.
External Prototype Pattern documentation: U{https://en.wikipedia.org/wiki/Prototype_pattern}
"""
def prototype(self, **attributes):
"""
Copy the prototype this object and optionally update attributes.
@param attributes: Keyword arguments of any attributes you wish to update.
@return: A copy of this object with the updated attributes.
"""
obj = deepcopy(self)
for attribute in attributes:
if callable(attributes[attribute]):
setattr(obj, attribute, MethodType(attributes[attribute], obj))
else:
setattr(obj, attribute, attributes[attribute])
return obj