Builder Pattern in PHP

The builder pattern is another creational pattern, meaning its purpose is the creation of objects. Similar to the purposes of Singleton, Multiton and Factory patterns.

However the builder pattern will not only create objects, but prepare them for your application too. The builder pattern actually uses the factory method pattern behind the scenes, but I’ll get onto that soon.

Continue reading

Factory Pattern in PHP

The factory pattern is one of the most commonly used design patterns, something you’ll definitely be glad to have in your toolbox. It’s also pretty simple to get to grips with and start reaping the benefits.

The purpose of any factory class, is to create and return instances of other classes, just like a real world factory creates products. There are two types of factory design patterns. One is called the factory method and the other is called an abstract factory. There is another not official pattern called simple factory. All are described in detail below. Let’s get going.

Continue reading

Multitons in PHP

In my last blog I covered the singleton design pattern (DP), showing how and when to use it. In this article I am going to cover a very similar design pattern called the multiton.

A multiton is almost exactly the same as a singleton, the one slight difference is a multiton can store multiple instances of itself. Contrary to a singleton, which can only store one instance of itself.

Continue reading