From the course: Design Patterns: Creational

Unlock the full course today

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

Flexibility and Factory Method

Flexibility and Factory Method

From the course: Design Patterns: Creational

Start my 1-month free trial

Flexibility and Factory Method

- [Narrator] Both the simple factory and the factory method pattern give us a lot of flexibility in our code when we anticipate needing to make changes to which concrete objects are instantiated over time. For instance, if our pizza store is adding new pizza types frequently, by using a factory pattern we ensure that we can add new pizza types without affecting existing client code that deals with pizzas. And for the factory method pattern specifically, we gain flexibility in families of products because we can change which factory to use to make products, again without affecting existing client code that deals with the factory. For instance, we could easily add a California pizza factory to make California-style pizzas. And this change would not require many changes in the client that deal with either the factories or the pizzas, because the client is referring to the factory and pizza interfaces. The code that's…

Contents