<?phpabstract class ParamHandler{protected $source;p rotected $param = array () ; Function __construct ($source) {$this->source = $source;} Function addparam ($key, $val) {$this->params[' $key '] = $val;} Function getallparams () {return $this->params;} Static function getinstance ($filename) { //is used to get subclass instances, file types are too long, only //need to add the IF statement here, and then write the sub-class if (Preg_match ("/\.xml$/i", $filename)) { return new xmlparamhandle ($filename); &nBsp; } return new textparamhandler ($ filename);} Abstract function write (); //guarantees that subclasses implement both methods Abstract function read ();}? >
And then the following is the subclass
Class Xmlparamhandle extends Paramhdndle{function write () {}function read () {}}class Textparamhandle extends Paramhdndle {function write () {}function read () {}}}
You can do this when you instantiate it.
$test = Paramhandler::getinstance ("./params.xml");
This will find the corresponding class instantiation based on the incoming Params.xml file.
Object-oriented programming, class switching