HomePHP Page 3 - Inheritance and Polymorphism in PHP: Building a Form Generator - Part II
There is a long list in your life: listing the full code for each subclass - PHP
In part two of this three-part series, we refresh our memory of Inheritance and subclasses from part one, and take our first stab at implementing a form generator.
As you can deduce from the above listed code, the subclass extends the base class, adding two extra properties: $value and $maxlength. The constructor accepts the base class parameters, plus the additional ones, and calls the base class constructor for setting up the $label, $name and $style properties. That's very simple to understand. Also notice that the subclass exposes its own "generateHTML()" method, which generates the corresponding HTML for an text input element, according to its properties.
Now, I think that you have an approximate idea of how the rest of the subclasses will look. And certainly you're correct. They're similarly defined, with a few different properties, according to the type of form element treated, but all of them offer the "generateHTML()" method. So, here's the definition for a hidden field subclass:
class hiddenFieldObject extends formObject {
var $value;
function hiddenFieldObject($label,$name,$style,$value){