Skip to content

Latest commit

 

History

History
45 lines (29 loc) · 1.46 KB

File metadata and controls

45 lines (29 loc) · 1.46 KB

Factory Method

In class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. This is done by creating objects by calling a factory method—either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes—rather than by calling a constructor.

More details: Wiki

Also known as

Virtual Constructor

Intent

Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

Diagram

Diagram


Example

Bellow you can see a code snippet of the pattern. php file sample

Obs: You can run it, executing the project clone.

Sample output

Example of output:

Project example

Bellow you can see a code snippet of the pattern.

References


Return to README.md