Generating Objects help!
Posted: Tue Apr 20, 2010 4:05 am
I'm building a simple database exporter that can export data from a given database to either XML or CSV format. I have separated the logic of the encoding into separate classes (XMLEncoder and CSVEncoder), that implements a common interface, so that more methods can be added later. I then have a main class (Exporter) that handles the rest of the export.
My question is, where do I instantiate an Encoder object? I currently have it wrapped up in the constructor of the main class (Exporter), but I'm not enforcing the interface and it feels a little wrong.
The constructor of my class is below
There isn't enough separated logic to go for a full blown factory pattern in my opinion, but all suggestions welcome!
My question is, where do I instantiate an Encoder object? I currently have it wrapped up in the constructor of the main class (Exporter), but I'm not enforcing the interface and it feels a little wrong.
The constructor of my class is below
Code: Select all
public function __construct($tableName, $exportType = 1, $exportDestination = 1, PDO $dbh) {
if(!empty($tableName)) {
$this->tableNames[] = $tableName;
}
$this->exportType = $exportType;
$this->exportDest = $exportDestination;
$this->DB = $dbh;
switch($this->exportType) {
case(self::XML):
$this->encoder = new XMLExportEncoder();
break;
case(self::CSV):
$this->encoder = new CSVExportEncoder();
break;
}