Skip to content

Instantly share code, notes, and snippets.

@gennad
Created March 2, 2011 18:12
Show Gist options
  • Save gennad/851399 to your computer and use it in GitHub Desktop.
Save gennad/851399 to your computer and use it in GitHub Desktop.
Prototype - GoF
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