For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > March 2005 > DB_DataObject Can getLink() return child class of DB_DataObject









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author DB_DataObject Can getLink() return child class of DB_DataObject
Ben Ford

2005-03-31, 8:57 pm

Is there an existing way to have getlink() return a child class of
DB_DataObject?

I was going to extend the getLink() to allow this but wanted some
feedback first.

Also, is there a better way to do this?

ie.
require_once 'DataObjects/Odb_item_line.php';
class ODBItemLine extends DataObjects_Odb_item_line {

public function getDescription()
{
$item = $this->getLink('odbItemId'); //returns wrong type!
return $item->toString(); //WILL NOT WORK!!
}
}

require_once 'DataObjects/Odb_item.php';
class ODBItem extends DataObjects_Odb_item {

/** @return string String representation of item.
* This can change based on various properties.
*/
public function toString()
{
//Fancy logic to calculate the name goes here...
return $itemName;
}
}


One way around this:
Put my extended code directly into the Auto-Generated class. But this
ties my class names to closely to the table names. I like the extra
degree of space I get when extending each class myself.

I would also have to use the factory method of instantiation which for
some reason I was trying to avoid...

Thanks in advance.

-Ben Ford
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com