This system, feel refreshing, believe in more practice, think more, will be familiar with.
http://www.jianshu.com/p/2450b785c329
#!/usr/bin/evn python#Coding:utf8classPizza (object):defPrepare (self, type):Print 'Prepare {type} pizza'. Format (type=type)defBake (self, type):Print 'Bake {type} pizza'. Format (type=type)defCut (self, type):Print 'cut {type} pizza'. Format (type=type)defbox (self, type):Print 'box {type} pizza'. Format (type=type)classCheesepizza (Pizza):def __init__(self): Self.name="Cheese Pizza"classClampizza (Pizza):def __init__(self): Self.name="Clam Pizza"classVeggiepizza (Pizza):def __init__(self): Self.name="Viggie Pizza"classSimplepizzafactory (object):defCreate_pizza (self, type): Pizza=NoneifType = ="Cheese": Pizza=Cheesepizza ()elifType = ="Clam": Pizza=Clampizza ()elifType = ="Veggie": Pizza=Veggiepizza ()returnPizzaclassPizzastore (object):def __init__(self, Factory): Self.factory=FactorydefOrder_pizza (self, type): Pizza=Self.factory.create_pizza (type) pizza.prepare (type) pizza.bake (type) pizza.cut (type) Pizz A.box (type)returnPizzaif __name__=='__main__': Store=Pizzastore (Simplepizzafactory ()) Pizza= Store.order_pizza ('Cheese') PrintPizza.name Pizza= Store.order_pizza ('Clam') PrintPizza.name Pizza= Store.order_pizza ('Veggie') PrintPizza.name
Python design pattern, creating simple Factory mode