HomePHP Using Different Objects in the Same Script for Polymorphs in PHP
Using Different Objects in the Same Script for Polymorphs in PHP
Welcome to the final part of a seven part series on building polymorphs in PHP. In a friendly fashion, this series gets you started constructing polymorph classes specifically in PHP 5. It shows you how to accomplish this by using first interfaces, then parent classes, and finally a proper combination of both.
And now that you've been introduced to the main goal of this group of tutorials, it’s time to review the topics discussed in the last one. In that article I explained how to build a couple of polymorph classes; both of them inherited structure from a simple interface and functionality from an abstract class responsible for rendering generic HTML elements.
Also, it’s necessary to recall that each of the classes constructed a specific HTML element through a common method called “render().” They also parsed its contents via another method, named“parseContent(),” which was inherited from the pertinent interface.
However, analyzing the construction of these sample classes separately would not be very helpful for understanding their polymorph nature. To solve this issue, in this final chapter of the series I’m going to develop a couple of scripts where the classes will be put to work together.
Now, it’s time to tackle the last part of this hopefully educational exercise in building polymorph classes with PHP 5. Let’s get going!