Php DAO是否应始终返回单个数据类型?

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

我们有一些POPOs(普通的旧PHP对象)/VO,如下所示:

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上,我们的控制器类只需要来自对象的一位数据。。。不是整个对象

是否最好:

  • 让DAO只返回SamplePopo对象,并通过getter(从控制器内部)获取我需要的数据:

  • 让DAO直接返回我需要的数据:

    //in the SampleVoDAO class:
    getOtherBitOfDataFromVOByID($id)  {
        $vo = getSampleVoById($id);
    
        return $vo->getOtherBitOfData;
    }
    
  • //in the SampleVoDAO class:
    getOtherBitOfDataFromVOByID($id)  {
        $vo = getSampleVoById($id);
    
        return $vo->getOtherBitOfData;
    }