In this tutorial we will study what is a design pattern and in the subsequent pages we will study about various design patterns supported by PHP. A design pattern is like a template which guides us to solve a problem. Design patterns are not finished design that can be transformed directly into code. In Object Oriented based design patterns we can get the interactions and relationships between classes or objects.
PHP Design Patterns:
A design pattern is like a template which guides us to solve a problem.
Design patterns are not finished design that can be transformed directly into
code. In Object Oriented based design patterns we can get the interactions and
relationships between classes or objects.
It is not necessary that every software patterns are design patterns. Design
patterns generally persists in the domain of modules.
Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides were introduced
design patterns and this was foreword by Grady Booch.
There are almost 23 patterns present and these are based on different
categories like Creation patterns, Structural patterns, and Behavioral
Now we will study five common design patterns in PHP 5:
PHP Factory Method
It is very common problem that sometimes we need to change a little in our coding and subsequently we have to change so many places like in other class, function etc. It is called tight coupling. In this case factory pattern helps us a lot. In the current tutorial we will study about factory method and how to implement this in PHP.
PHP Singleton Method
In the current php tutorial we will study about singleton pattern of PHP, which is another type of designing pattern. Examples will help you understand in better way.
PHP Observer Method
In this pattern one object make itself observable and other objects observed it. The object which is observed is called subject. When the observable object changes it passes some message to the observer and the observer uses those message according to their need..