Code: Select all
class FileList
{
protected $basePath;
protected $list;
public function getBasePath() {return $this->basePath;}
public function get() {return $this->list;}
...
}Code: Select all
class Writer
{
protected $fileList;
public_construct(FileList $fileList)
{
$this->fileList = $fileList->get();
$this->basePath = $fileList->getBasePath();
}
public function write()
{
foreach($this->fileList .....
}
}Code: Select all
class Writer
{
protected $fileList;
protected $basePath;
public_construct(Array $fileList, $basePath)
{
$this->fileList = $fileList;
$this->basePath = $basePath;
}
public function write()
{
foreach($this->fileList .....
}
}Code: Select all
class Writer
{
protected $fileList;
protected $basePath;
public_construct(Array $config)
{
$this->fileList = $config['fileList'];
$this->basePath = $config['basePath'];
}
public function write()
{
foreach($this->fileList .....
}
}The question is: Which is better -coupling by interface (i.e. first case), or moving it into the function (constructor) signature (i.e. 2nd,3rd case). Or maybe an Adapter pattern?
Second question: Which is better from (Unit)Testing point of view?
EDIT: First example wasn't accurate enough. Fixed.