I'm reading about Design Patterns in PHP, and, I'm skeptical of the code which I'd written to implement the Factory Design Pattern.
Does this code implement REAL Factory Design?
And, Do I need to use any interface here?
The code is:
class DBFactory
{
const MYSQL = 1;
const ORACLE = 2;
const SQLITE = 3;
private $objectTxt = null;
function __construct($type)
{
if ($type == self::MYSQL) {
$this->objectTxt = 'MySQL Object';
return ; //MySQL Object
}
else if ($type == self::ORACLE)
{
$this->objectTxt = 'Oracle Object';
return ; //Oracle Object
}
else if ($type == self::SQLITE)
{
$this->objectTxt = 'SQlite Object';
return 'SQLite Object'; //SQLite Object
}
}
function __toString() {
return $this->objectTxt;
}
}
Aucun commentaire:
Enregistrer un commentaire