dongshang4984 2012-01-31 16:25
浏览 24
已采纳

模型作为Zend Framework和服务层中的纯数据对象

It has become common to treat models in ZF as pure data objects, i.e. a class instance with a bunch of attributes and getters/setters.

class Model_User {
  public $id;
  public $name;
  ...
}

What I'm wondering is whether or not it makes sense to, for example, instantiate such an object in a controller and pass it to a service layer, or whether or not the service layer should itself be responsible for instantiating these objects... You would not instantiate a Zend_DbTable class directly in the controller, so does it make much sense to instantiate a Model_User in a controller to pass it to a service?

  • 写回答

1条回答 默认 最新

  • dthdlv9777 2012-01-31 17:25
    关注

    I don't see a problem with doing it this way. Data Transport Objects (DTO) are meant to pass information between layers and/or modules. In my opinion this is no different that using arrays and it certainly is easier than using arrays.

    Here is another discussion over DTOs - What is Data Transfer Object?

    And Martin's definition on DTOs - http://martinfowler.com/eaaCatalog/dataTransferObject.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计