Home arrow PHP arrow Decoupling the Interaction Between Objects with Factory Methods

Decoupling the Interaction Between Objects with Factory Methods

Welcome to the fifth part of a six-part series on implementing factory methods in PHP 5. In this part, I show how the removal of a factory method inside the constructor of the class that originates persistent objects can produce a huge impact in the way that those objects handle its dependency, which happens to be a database handler object.

TABLE OF CONTENTS:
  1. Decoupling the Interaction Between Objects with Factory Methods
  2. Review: implementing a simple factory method in PHP 5
  3. Using a factory method more efficiently
  4. Putting the sample classes to work
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
December 14, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Unquestionably, defining factory methods during the development of an application is a task that both programmers and web developers must tackle frequently. In the case of PHP 5, this process is fortunately a no-brainer one, due to the versatility of its robust object model and its flat learning curve.

While the correct implementation of factory methods in PHP 5 is certainly a tame procedure for developers who have solid experience, it can be quite challenging and intimidating for those who are currently taking their first steps in object-oriented web development.

So, if youíre interested in learning the key concepts that surround the definition of factory methods in PHP 5, then start reading this article right away!

And now that you've been introduced to the subject of this series, itís tine to review the topics that were discussed in the last article. In that installment of the series, I demonstrated how useful a factory method can be for reducing the number of instances of a database handler that need to be used by other classes.

Basically, this factory method returned a Singleton instance of this database handler, which was shared seamlessly by a couple of persistent objects, thus improving the way that these objects managed their interaction with this dependency.

However, in its current state, the class that originates those persistent objects is still responsible for creating the database handler, which is detrimental in terms of building truly decoupled classes. Thus, in this fifth part of the series Iím going to modify the signature of the class that models persistent objects, which will contribute to making them more independent from the aforementioned database handling object.

Now, itís time to leave the preliminaries behind and learn more useful things about building factory methods in PHP 5. Letís go!



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: