I have a base object (form_field_base) that is extended/inherited by other objects in the form of:
class form_field_base {
// Lots of code
}
class form_field_text extends form_field_base {
// Lots of code
}
class form_field_email extends form_field_text {
// Extending the text object to update validation, and set input type="email"
}
class form_field_file extends form_field_base {
// Lots of code, for example uploading files
}
The "form_field_base" provides helper methods that all of the form field types use, for example a html() function calls the specific object (form_field_email::html_input) to get the field, then put that in a string with the standard tag, etc.
All of these objects are used by many projects.
However, this latest project I'm working on requires the "form_field_base" object to be customised to allow the setting of some help text, a feature that no other project requires, and if future projects do, it will probably be done differently.
So how should this have be organised?
Ideally I won't have a complete copy of "form_field_base", as that would cause code duplication.
And it does seem like quite a bit of overhead to have dummy intermediate objects:
class form_field_base_common {
// Lots of code
}
class form_field_base extends form_field_base_common {
// By default is empty
}
class form_field_text_common extends form_field_base {
// Lots of code
}
class form_field_text extends form_field_text_common {
// ...
}
class form_field_email_common extends form_field_text {
// Extending the text object to update validation, and set input type="email"
}
class form_field_email extends form_field_email_common {
// ...
}
class form_field_file_common extends form_field_base {
// Lots of code, for example uploading files
}
class form_field_file extends form_field_file_common {
// ...
}
Taking that each one has it's own file, which is auto-loaded (either a from a project specific location, if it exists, or from a common folder that all projects can access)... that is already 8 files that need to be found, opened, parsed, etc, just for supporting a form.
Surly there has to be a better way?