1、Bryan Li6/18/2007Common if(type.equals(“chees“) pizza = new CheesePizza(); else if (type.equals(“greek“) pizza = new GreekPizza(); else if (type.equals(“pepperoni“) pizza = new PepperoniPizza();pizza.prepare();pizza.bake();pizza.cut();pizza.box();return pizza;Simple Pattern Mending design of pizza s
2、torySimple Pattern Add SimplePizzaFactory Classpublic class SimplePizzaFactory public static Pizza createPizza(String type) Pizza pizza = null;if (type.equals(“chees“) pizza = new CheesePizza(); else if (type.equals(“greek“) pizza = new GreekPizza(); else if (type.equals(“pepperoni“) pizza = new Pep
3、peroniPizza();return pizza;public class PizzaStore SimplePizzaFactory factory;public Pizza orderPizza(String type) Pizza pizza = SimplePizzaFactory.createPizza(type);pizza.prepare();pizza.bake();pizza.cut();pizza.box();return pizza;Simple Pattern Feature you dont need to instantiate an object to mak
4、e use of the create method you cant create sublcass and change the behavior of the create method Not typical design pattern- more of a programming idiom Fade Format Merge Creator into ConcreteProduct Simple Pattern Advantage Reuse the code that create object Disadvantage If product has any change, Creator class should be impacted. OO Design Principle OCP: if add new type of product, in the view of client and product, it conform to OCP, but in the view of Factory Creator, it does not.