I have a class that is a container for a bunch of module objects. Right now the container takes in an array of file paths, then includes the files and instantiates the modules
class module {
function execute();
}
class container {
public $Name;
public $Modules;
public __construct($Obj){
$this->Name = $Obj->Name;
foreach($this->Modules as $M){
include_once($M);
$className = $this->GetClassName($M);
$this->Modules[] = new $className;
}
}
public execute(){
foreach($this->Modules as $M){
$M->execute();
}
}
}
I'm not certain what the best way to refactor this so that it is easily testable is.
class containerFactory{
public function createContainer($Obj){
$C = new Container($Obj);
$C->InstiateModules();
return $C;
}
}
class container{
public function InstiateModules(){
$tmp = array();
foreach($this->Modules as $M){
include_once($M);
$className = $this->GetClassName($M);
`enter code here`$this->Modules[] = new $className;
}
$this->Modules = $tmp;
}
public function __construct($Obj){
$this->Name = $Obj->Name;
$this->Modules = $Obj->Modules;
}
}
Any suggestions as to what else I should do? Thanks