HomePHP Generating Web Pages with the Flyweight Pattern in PHP 5
Generating Web Pages with the Flyweight Pattern in PHP 5
Unnecessary and balanced instantiation of PHP classes are issues that can be easily solved by using the flyweight design pattern. If you want to learn more about it, you should start reading this article. Welcome to the final part of the series “Using the flyweight pattern with PHP 5.” As you may have guessed, this series walks you through the implementation of this helpful pattern with PHP, and shows you how to apply it in concrete cases.
If you've been a patient reader and already went through the first part of this series, then you'll know what the flyweight pattern is about. However, if that's not the case, let me offer you a quick introduction to it so you can grasp more easily the set of examples that I plan to include in this article.
Essentially, when the flyweight design pattern is applied, there's one class that controls programmatically the number of objects created across a given application. This implies that the pattern can be used to avoid the unnecessary instantiation of a particular class, and to introduce an improvement in the web server on which the application is running.
Of course, this definition may sound a bit confusing at first, since the implementation of flyweight classes requires some practice. It's certainly a concept that can be applied to different topics on pattern-based PHP programming as well.
Nonetheless, you shouldn't feel intimidated by the potential complexity of the subject. In this final part of the series, I'm going to teach you in a step-by-step format how to create in PHP 5 a flyweight class to balance the instantiation of objects that will be used to generate web documents on the fly. Hopefully, by the end of this article, you should have acquired a considerable background in how to apply the flyweight pattern in a real-world situation.
With the preliminaries out of the way, let's continue learning more about how to create flyweight classes with PHP 5. Let's go!