As you’ll recall from the section that you just read, in this final part of this article I’m going to set up a practical example that shows how to use all the classes that were previously created to validate different types of user-supplied data. Indeed, this sounds really interesting and hopefully the code samples that you’ll see in a moment will help you grasp more easily how the bridge pattern can be implemented with a few simple PHP 5 classes. Having said that, here is the corresponding set of try-catch blocks, which demonstrate the correct usage of each of the data validation classes that were built in previous sections, and the “BridgeDataValidator” class as well. Have a look at these examples, please:
All right, I think that the group of code samples that were shown above are more than enough for demonstrating the correct implementation of the bridge design pattern in PHP 5. In addition, you should notice how in each case I provided the “BridgeDataValidator” object with an invalid input parameter, a condition that obviously throws the corresponding exception and also makes the script display the respective error message. As I have said with many other articles that I wrote for the prestigious Developer Shed network, don’t hesitate to introduce your own modifications to all the sample classes that were shown here. This will help you to acquire a more intimate knowledge of how the bridge pattern works. It’s a really educational experience, trust me! Final thoughts Unfortunately, we’ve come to the end of this article. However, I hope this tutorial has been instructive for you, specifically with reference to applying the bridge pattern as part of a more complex data validation application. As you saw, the process is really straightforward and also educational. However, this journey is not over yet. In the last part of the series, I’m going to teach you how to use the mentioned pattern to build an abstraction layer for working with MySQL. See you in the final article!
blog comments powered by Disqus |