HomePHP Decoupling the Validation of Data with Bridge Classes in PHP 5
Decoupling the Validation of Data with Bridge Classes in PHP 5
Are you interested in expanding your existing knowledge of different structural design patterns with PHP 5? Then look no further because you’ve come to the right place. Welcome to the second installment of the series “Using Bridge Classes with PHP 5.” This group of three articles walks you through the basics of how to apply the bridge pattern in PHP-based applications, and it also teaches you how to use bridge objects in real world development environments.
Provided that you already went through the first tutorial of the series, and learned how to create bridge classes with PHP 5, then I’ll assume that the logic that drives the mentioned pattern is quite familiar to you. However, if you’re taking the first steps on this topic, let me give you a brief introduction to how this pattern works, thus the upcoming examples that I plan to include in this article will be much easier to understand.
Essentially, in the bridge design pattern, a specific class and its respective implementation reside on different class hierarchies, which is accomplished without using an abstract class. As you’ll possibly imagine, this model is very convenient for decoupling the generic structure of the class in question from its concrete definition, since the corresponding implementation is achieved by one or more “bridged” classes.
To clarify the previous definition, in the preceding article I developed a concrete example in which a bridge class behaved as an intermediate entity for saving a target object to different storage locations. Even when this example didn’t have an immediate application in real situations, it was really useful for demonstrating how the bridge pattern can be applied in PHP 5.
However, this instructive journey has just started. In the course of this second tutorial, I’m going to show you how to create a bridge class which will come in handy for decoupling the validation of user-supplied data. There will be a class that defines generically how certain data must be verified, while others will implement different validation methods.
Having explained what this article is about, let’s go ahead and continue learning more about this powerful pattern. Let’s go!