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
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap

Dev Shed Tutorial Topics: