class Shape object staticmethod def factory type if type Circle return

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class Shape(object):
@staticmethod
def factory(type):
if type == "Circle": return Circle()
if type == "Square": return Square()
assert 0, "Bad shape creation: " + type
class Circle(Shape):
def draw(self): print("Circle.draw")
def erase(self): print("Circle.erase")
class Square(Shape):
def draw(self): print("Square.draw")
def erase(self): print("Square.erase")