课程: Programming Foundations: Design Patterns

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

Using the Factory Method pattern

Using the Factory Method pattern

- [Instructor] To create a pizza, we first need to instantiate the kind of store we want. Imagine you're choosing between walking into a New York-style pizza store, or a Chicago-style pizza store. Once we're in the store, we can order a pizza. Remember, this method is implemented by the abstract class, PizzaStore. No matter which pizza store we're in when we make an order, we're guaranteed to get the same, brilliant pizza-making algorithm to produce quality pizzas. The first step in the orderPizza algorithm is to create the pizza. The createPizza method is implemented by the individual stores. So, in a New York pizza store, we'll get the method implemented by that store. We pass the type of pizza along to the createPizza method. This method creates the right kind of pizza based on the type. And once it's returned to the orderPizza method in the store, the orderPizza method can prepare the pizza for the…

内容