I have a simple script based on a single class. I want to add several features to it, but only as an “opt-in” version - a plugin.
Class thing = {
public function __construct() {
// ...
}
public function stuff() {
// ...
}
}
/* in thing_extension.php: */
Class thing_extension extends thing {
public function stuff() {
// everything in here runs instead of the original stuff()
// this function is basically the same as stuff() but has the extra features
// they're not just tagged on, they overwrite a lot of the original code
}
}
It feels a little dirty because if you add thing_extension, the original stuff() becomes obsolete and there’s a large chunk of useless code lying about.
Am I on the right track here or is there a better (but still simple) way of doing this?