From the course: Design Patterns: Creational

Unlock the full course today

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

The Factory Method pattern

The Factory Method pattern

From the course: Design Patterns: Creational

Start my 1-month free trial

The Factory Method pattern

- [Instructor] In the Simple Factory Pattern, we have a class, SimpleFactory, with a method, createProduct, that creates the correct concrete product. Factory Method is a little different. In Factory Method we have a Factory class that operates on products we create but leaves the decision about which product to make to the Factory subclasses. The Factory superclass specifies an abstract method, createFactory, that all Factory subclasses must implement. Factory Method is a little different. In Factory Method we have a Factory class that operates on products we create, but leaves the decision about which product to make to the Factory subclasses. The Factory superclass specifies an abstract method, createProduct, that all factory subclasses must implement. This is the Factory Method that gives the pattern its name. In addition, we have a parallel hierarchy of products, with an abstract Product superclass, like we saw in…

Contents