Home arrow PHP arrow The Basics of Using the Factory Pattern in PHP 5

The Basics of Using the Factory Pattern in PHP 5

If you need to create multiple objects that belong to the same family, you probably want to use the factory pattern. This three-part series takes a close look at using the factory pattern in PHP.

  1. The Basics of Using the Factory Pattern in PHP 5
  2. Developing some basic factory classes
  3. Defining some array processing classes
  4. Testing the functionality of the factory pattern
By: Alejandro Gervasio
Rating: starstarstarstarstar / 13
June 25, 2007

print this article




Many PHP developers with a solid background in pattern-based programming know that there are certain patterns that are more difficult to grasp than others. This is due mostly to the inherent diversity of this fascinating terrain, where purist concepts about software design merge flawlessly with simple, natural common sense.

Indeed, design patterns present singularly interesting facets. They are conceived as proven solutions to specific programming-related issues, but at the same time, have a certain dose of improvisation, which makes them even more attractive. Logically, if you think carefully about this concept, you'll understand more clearly the meaning of this question: how many times did you find yourself applying a particular pattern without knowing what you were actually doing? Perhaps dozens, even hundreds of times.

Nevertheless, the most important thing to notice here is that a concrete problem can be solved by implementing the logic of a particular pattern, which means that certain software development issues can be addressed in a more intuitive way than others. And definitely, the factory pattern is an excellent example of this situation, since many developers use it frequently, even if they're taking their first steps into the object-oriented programming arena.

Admittedly, it's common to see during the development of a given PHP application that one or more classes are created with the purpose of returning a specific type of object to client code, where the object must conform to the specifications of a concrete environment. As you may have guessed, this is precisely the theoretical definition of the factory pattern.

Summarizing, the factory pattern can be really useful when it comes to creating multiple objects that belong to the same family. In this three-part series I'm going to take a close look at it, and also demonstrate its remarkable functionality by showing you a decent variety of code samples, so you can start quickly including this pattern into your own PHP applications.

With the preliminaries out of the way, now let's move on together and begin discovering how to apply the factory pattern with PHP. It's going to be an educational journey, believe me!

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