HomePHP Handling Cookies and File Data with the Factory Pattern in PHP 5
Handling Cookies and File Data with the Factory Pattern in PHP 5
Any PHP developer who has been using the object-oriented paradigm for a while for developing web applications knows that the factory design pattern can be really useful when it comes to creating multiple objects across a specific programming context. However, if you're interested in filling some knowledge gaps that you might have about this handy pattern, then this article is possibly what you're looking for.
Welcome to the second tutorial of the series that began with "Using the Factory Pattern in PHP 5." Made up of three instructive parts, this series walks you through the foundations of developing factory classes with PHP, and also shows you how to implement this popular design pattern in real world situations.
Now, having properly introduced the subject of this series, let me touch upon what was covered in the preceding article to refresh your memory. As you'll probably recall, I demonstrated in a friendly way how to build a pair of concrete factory classes. These came in useful for spawning different array-processing objects in accordance with the specifications of their corresponding contexts.
Of course, defining the aforementioned factory classes was merely an introduction to exploring the remarkable functionality provided by the homonymous pattern, and it should be admitted that there are many other cases in which the pattern can be used successfully. Nevertheless, I do think that all the hands-on examples shown in the first article of the series were explicit enough to illustrate how a concrete factory class works and how it can be called statically within a specific programming environment.
So far, so good right? At this stage you should have a more accurate idea of how to include the factory pattern into your own PHP applications, at least at a very basic level. But don't you worry because this scenario is going to change quickly, since in this second tutorial I'm going to teach you how to take advantage of the capacity offered by the pattern to create objects that are capable of saving data to different locations, including files and cookies.
Hopefully, this experience will be educational and serve to expand your existing skills on pattern-based programming with PHP 5 even more.