HomePHP Applying the Dependency Injection Pattern and Factory Methods in PHP 5
Applying the Dependency Injection Pattern and Factory Methods in PHP 5
Welcome to the final part of a series on implementing factory methods in PHP 5. Composed of six approachable tutorials, this series uses numerous hands-on examples to teach you how to define specific methods within your own PHP programs. These methods return to client code instances from their originating classes, and from other classes as well.
And now that you know what to expect from this series of articles, it’s time to quickly review the topics that were covered in the last tutorial. In that part of the series I built a simple application in PHP 5 composed of two classes for its building blocks. The first was merely a basic MySQL abstraction class, while the second was a storage class that took advantage of the functionality given by the first to persist across different HTTP requests.
Of course, the interaction established between these two classes was achieved via a factory method that allowed sharing of the same database handler between multiple persistent objects. The process demonstrated how useful this type of method can be in such a situation.
However, I’d like to finish this series on building factory methods by explaining how the database-driven application developed in the preceding article can be optimized even more with a few little tweaks. In this case, thanks to a simple implementation of the Dependency Injection pattern, it’ll be possible to completely avoid the utilization of the factory method.
Do you want to learn how this will be done? Then start reading now!