HomePHP Using Directory Iterators and MySQL with Adapter Objects with PHP
Using Directory Iterators and MySQL with Adapter Objects with PHP
If you’re a PHP programmer who’s searching for a comprehensive tutorial on how to create adapter classes with PHP 5, them look no further. Welcome to the final installment of the series “Implementing adapter objects with PHP.” Made up of two parts, this series teaches you how to implement the adapter design pattern in PHP 5, and it accompanies the corresponding theory with educational examples.
Quite possibly, you'll remember that in the first part of the series I went through the definition and application of this design pattern, and additionally provided you with some illustrative code samples to demonstrate how the functionality of a given class can be easily expanded without using inheritance.
Now, speaking more specifically, you'll recall that the hands-on example that I developed in the first article was focused on creating a directory adapter class. This class was originally defined for extending the functionality of another one, in this case conceived as a generic directory processor.
Of course, the best thing about building an adapter class rests on the fact that this process is entirely performed without the need to use a more conventional approach, such as applying inheritance.
However, it should be noticed that the implementation of the adapter pattern with PHP is applicable particularly in those situations where working directly with subclasses is nearly impossible, or when a certain application has been so poorly developed that the only way to tackle a specific problem is by defining a new class that conforms to a predefined model.
In all other situations, inheritance is probably the best approach to follow when the functionality of an existing class must be extended inside the context of a given application.
All right, now that I recapitulated quickly the topics covered in the first article, let me tell you what you'll learn in this one. Provided that you understand the basic concepts of the adapter pattern, in this final tutorial, I'll show you how to use it in conjunction with the "DirectoryIterator" class, bundled with PHP 5, and with a couple of MySQL wrappers as well.
Having established the subject of this article, let's get started.