课程: Programming Foundations: Design Patterns

今天就学习课程吧!

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

The Factory Method pattern

The Factory Method pattern

- [Instructor] We just used a simple factory to create our pizza store. Notice that the Simple factory allows us to decouple the process of creating objects from the clients that use those objects. In our case, we used a simple factory to create pizzas so that the pizza store didn't have to worry about the details of the various pizza types. Instead it could focus on the pizza preparation and delivery. This approach works well. But what happens if we have multiple store franchises? Let's say we have two pizza stores and one wants to make New York-style pizza and the other one wants to make Chicago-style pizza. Now we're in the situation where we're going to need to use two different factories to make two different styles of pizza. We know the downside of that, code duplication. It's also presumably our process. That is all that code that isn't changing that has made it successful and we want to keep that common to…

内容