Created
March 2, 2011 18:12
-
-
Save gennad/851399 to your computer and use it in GitHub Desktop.
Prototype - GoF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from copy import deepcopy | |
class Prototype: | |
def __init__(self, example): | |
self.example = example | |
def clone(self): | |
return deepcopy(self.example) | |
class ToyotaCar: | |
pass | |
class FordCar: | |
pass | |
def clone(prototype): | |
return prototype.clone() | |
p1 = Prototype(ToyotaCar()) | |
p2 = Prototype(FordCar()) | |
obj1 = p1.clone() | |
print obj1 | |
obj2 = p2.clone() | |
print obj2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment