HomePHP Factoring Content Boxes with the Factory Pattern in PHP 5
Factoring Content Boxes with the Factory Pattern in PHP 5
Working with factory classes is a rather common process for many PHP developers who build object-based applications on a frequent basis. If you want to find out how to make this helpful class work for you, then this group of articles might be what you need. Welcome to the final installment of the series that began with "Using the Factory Pattern in PHP 5." In three parts, this series goes through the key concepts of implementing the factory pattern with PHP, and complements theory with numerous and educational code samples.
Now that I have introduced the subject of this series, let me remind you of some of the most important topics covered in the previous tutorial. As you learned earlier, implementing the factory pattern using an extremely friendly scripting language like PHP is actually a no-brainer process that can be performed with minor hassles.
Creating a simple yet effective factory class, which can be easily provided with the capacity for spawning multiple objects across a given application, is a procedure reduced to something as basic as defining a method for the class in question that has the ability to return to client code a certain type of object, according to the specifications of a determined context.
Besides, as I clearly demonstrated by the copious hands-on examples included in the two previous tutorials of the series, working with only one instance of the factory class is an issue that can be addressed by different approaches. These include applying the Singleton pattern, or even better, calling statically its factory method.
Now that I mentioned it, I used this last approach with all the code samples shown so far; it's one of the most effective techniques utilized by many PHP programmers. It allows you to create specific objects without having to deal with a concrete instance of a factory class.
However, I'd like to put the tiny details of the factory pattern to the side (at least momentarily) and introduce the topics that I plan to cover in this final article of the series. In this last tutorial I'm going to teach you how to implement this useful pattern to build a bunch of highly-customizable content boxes, which can be quickly included into any web page.
Now that you know what this article is about, let's move on together and learn how to build these popular and handy elements of today's web development by using the functionality provided by the factory pattern. Let's get started!