Php DAO是否应始终返回单个数据类型?
我们有一些POPOs(普通的旧PHP对象)/VO,如下所示:Php DAO是否应始终返回单个数据类型?,php,dao,Php,Dao,我们有一些POPOs(普通的旧PHP对象)/VO,如下所示: class SampleVO { private $id; private $name; private $otherBitOfData; //constructor //getters and setters } 我们还有DAO从数据库中提取这些对象: class SampleVoDAO { getSampleVoById($id) { //returns
class SampleVO {
private $id;
private $name;
private $otherBitOfData;
//constructor
//getters and setters
}
我们还有DAO从数据库中提取这些对象:
class SampleVoDAO {
getSampleVoById($id) {
//returns the SamplePopo object fetched by ID.
}
getSampleVoByName($id) {
//returns the SamplePopo object fetched by Name.
}
//etc...
}
在occcasison上,我们的控制器类只需要来自对象的一位数据。。。不是整个对象
是否最好:
//in the SampleVoDAO class:
getOtherBitOfDataFromVOByID($id) {
$vo = getSampleVoById($id);
return $vo->getOtherBitOfData;
}
//in the SampleVoDAO class:
getOtherBitOfDataFromVOByID($id) {
$vo = getSampleVoById($id);
return $vo->getOtherBitOfData;
}