From the course: Programming Foundations: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using the Factory Method pattern

Using the Factory Method pattern

From the course: Programming Foundations: Design Patterns

Start my 1-month free trial

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…

Contents