工厂模式:
定义了一个创建对象的接口,但由子类决定要实例化的类是哪一个。工厂方法让类本实例化推迟大子类。
设计原则:
要依赖抽象,不要依赖具体类。
1. 定义PizzaStore的抽象类
2.定义Pizza的抽象类
3. 实现PizzaStore类
ChicagoPizzaStore
NYPizzaStore
4. 实现Pizza类
ChicagoStyleCheesePizza
NYStyleCheesePizz
5.编写测试程序
6.输出结构
Preparing NY Style Sauce and Cheese Pizza
Tossing dough...
Adding sauce...
Adding toppings:
Crated Reggiano Cheese
Bake for 25 minutes at 350
Cutting the pizza into diagnal slices
Place pizza in official PizzaStore box
Ethan ordered a NY Style Sauce and Cheese Pizza
Preparing Chicago Style Sauce and Cheese Pizza
Tossing dough...
Adding sauce...
Adding toppings:
Shredded Mozzarella Cheese
Bake for 25 minutes at 350
Cutting the pizza into square slices
Place pizza in official PizzaStore box
Joel ordered a Chicago Style Sauce and Cheese Pizza