Home arrow PHP arrow 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.

  1. Applying the Dependency Injection Pattern and Factory Methods in PHP 5
  2. Review: the classes so far
  3. Removing the factory method from the MySQL class
  4. Creating persistent objects without a factory method
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
December 15, 2009

print this article



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!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: