🎉 Hooray! After 3 years of work, I've finally released the ebook on design patterns! Check it out »
Factory Method

Factory Method in PHP

Factory method is a creational design pattern which solves the problem of creating product objects without specifying their concrete classes.

Factory Method defines a method, which should be used for creating objects instead of direct constructor call (new operator). Subclasses can override this method to change the class of objects that will be created.

If you can’t figure out the difference between Factories, Factory Method & Abstract Factory patterns, then read our Factory Comparison guide.

Learn more about Factory Method

Usage of the pattern in PHP

Complexity:

Popularity:

Usage examples: The Factory Method pattern is widely used in PHP code. It’s very useful when you need to provide a high level of flexibility for your code.

Factory Method in Other Languages

Factory Method in Java Factory Method in C# Factory Method in Python Factory Method in Ruby Factory Method in Swift Factory Method in TypeScript