且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Zend Framework 正确创建域?

更新时间:2023-11-15 23:19:16

域模型不扩展任何内容.它们只是用于封装业务逻辑的普通类.他们可能使用数据访问对象,所以在类内部可能有一个行数据网关对象的protected实例.Row 对象通常比 Table 对象更接近地表示域的实例.此外,您始终可以使用RowgetTable() 方法获取Table 对象.

Domain Models extend nothing. They're just plain classes you use to encapsulate business logic. They may use data access objects, so there may be a protected instance of a row data gateway object inside the class. A Row object usually represents an instance of the domain more closely than a Table object. Besides, you can always get the Table object with the Row's getTable() method.

通常,DM 类具有一个接口,其中包含与您可以使用该类执行的更高级别操作相对应的方法.但您不一定要显示所有数据访问操作.

Typically DM classes have an interface with methods corresponding to higher-level operations you can do with that class. But you don't necessarily want to surface all data access operations.

class Person {
  // Zend_Db_Table_Row object
  protected $data; 

  public function subscribeToService(Service $service) { ... }

  public function sendMailTo(Person $recipient) { ... }

  public function changePassword($newPassword) { ... }
}

我去年 春季也写了关于这个主题的博客,并在 ZF 邮件列表上写了它 最近.

I also blogged about this subject last spring, and wrote about it on the ZF mailing list recently.

就教程和资源而言,请尝试 http://domaindrivendesign.org/

As far as tutorials and resources, try http://domaindrivendesign.org/