|
|
Posted by LiveFreeAndRoam on 06/25/06 12:16
Hi,
I am on a steep learning curve... I would appreciate your advice on a
design decision regarding class hierachies. (See below)
Especially notice that my Table class creates the DataAccess object.
------------------------------------------------
class DataAccess extends MDB2 {
// DataAccess properties and methods
var $db;
function __construct($dsn) {
$this->db =& MDB2::factory($dsn);
}
}
class Table {
// table properties and methods
var $dao;
function __construct() {
$this->dao = new DataAccess(); // <<< OK?
}
}
class Product extends Table {
// Product properties and methods
}
--------------------------------------------------
One issue I have noticed is that when I attempt to recover the Product
Object from the $_SESSION superglobal that the DataAccess object is
unusable. MDB2 complains with:
MDB2 Error: not found: could not find MDB2 instance
OK, I can overcome this error by simply creating a new Product object and
copying the data from the $_SESSION variable into the newly created object.
Though, this seems terribly inefficient. I would have preferred to simply
say:
$product = unserialize($_SESSION['product']);
$product->query($query);
Instead I have to do this:
$sessprod = unserialize($_SESSION['product']);
$product = new Product();
$product->setProperties($sessprod->getPropertiesExcludingDao());
$product->query($query);
Of course, I have considered creating a DataAccess object outside of my
table definition. This would require some tedious changes to the code-base,
since everywhere I create a Table object, I would need to also create a
DataAccess object.
Before I go ahead with changing this, I would really appreciate your input.
Will I be trading one problem for another? Is there a better way to design
this?
Kind regards,
LFaR.
[Back to original message]
|