© Kelt Dockins 2017

Kelt Dockins, Design Patterns in PHP and Laravel, 10.1007/978-1-4842-2451-9_8

8. Simple Factory Method

Kelt Dockins

(1)Dolph, Arkansas, USA

$> git checkout simple_factory_method

The simple factory is not an design pattern you find in the original 90s Gang of Four design patterns book. Yet it is an extremely useful way to create objects—so useful that I made a chapter for it.

Intent

The simple factory method simplifies the process of creating new concrete objects.

Applications

Using a simple factory makes code cleaner and easier to deal with. This pattern can be applied when you want to create an object that has dependencies. This pattern can be used to refactor places in code where products are created. One might say that this ...

Get Design Patterns in PHP and Laravel now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.