In accordance with the concepts that I deployed in the previous section, here is an illustrative example that shows how to use some of the data checking classes that you learned before. This will demonstrate how useful and powerful polymorphism can be. Take a look at the following code sample, please: try{ As you can see, the sample script shown above demonstrates in a friendly fashion how to use some of the classes created previously to validate different types of data. The respective objects display a primitive message indicating whether or not a particular value is valid, but this can be easily changed to fit your personal needs. As usual, feel free to tweak the source code of all the classes shown in this article, so you can eventually acquire a better understanding of how polymorphism can be used to build more efficient PHP applications. Final thoughts Finally, we've come to the end of this series. Hopefully, after reading these three tutorials, you'll have a more accurate idea of how to take advantage of the functionality provided by polymorphism to build more solid and robust object-based PHP applications. As expressed earlier, polymorphism can be applied successfully in those situations where you need to work with a bunch of objects that belong to the same family, but eventually can have different behaviors. See you in the next PHP tutorial!
blog comments powered by Disqus |