001package headfirst.factory.pizzafm; 002 003public class DependentPizzaStore { 004 005 public Pizza createPizza(String style, String type) { 006 Pizza pizza = null; 007 if (style.equals("NY")) { 008 if (type.equals("cheese")) { 009 pizza = new NYStyleCheesePizza(); 010 } else if (type.equals("veggie")) { 011 pizza = new NYStyleVeggiePizza(); 012 } else if (type.equals("clam")) { 013 pizza = new NYStyleClamPizza(); 014 } else if (type.equals("pepperoni")) { 015 pizza = new NYStylePepperoniPizza(); 016 } 017 } else if (style.equals("Chicago")) { 018 if (type.equals("cheese")) { 019 pizza = new ChicagoStyleCheesePizza(); 020 } else if (type.equals("veggie")) { 021 pizza = new ChicagoStyleVeggiePizza(); 022 } else if (type.equals("clam")) { 023 pizza = new ChicagoStyleClamPizza(); 024 } else if (type.equals("pepperoni")) { 025 pizza = new ChicagoStylePepperoniPizza(); 026 } 027 } else { 028 System.out.println("Error: invalid type of pizza"); 029 return null; 030 } 031 pizza.prepare(); 032 pizza.bake(); 033 pizza.cut(); 034 pizza.box(); 035 return pizza; 036 } 037}