php – 在Zend中,为什么我们使用DB Model类和Mapper类作为两个独立的?

我正在研究zend项目,我指的是其他zend项目来创建新的Zend Project.But我不喜欢盲目地遵循该项目而不理解.在Zend Directory结构中,在Model类中,我看到的类主要有两种类型,如in
- models
   - DbTables
        - Blog.PHP  //Extends Zend_Db_Table_Abstract
   - Blog.PHP       // Contains methods like validate() and save()
   - BlogMapper.PHP // Also Contains methods like validate(Blog b) & save(Blog b)

为什么遵循这种特定的结构?
这是分开Object类和Database模型类吗?

请解释.

DataMapper is a design pattern from Patterns of Enterprise Application Architecture.

The Data Mapper is a layer of software that separates the in-memory objects from the database. Its responsibility is to transfer data between the two and also to isolate them from each other. With Data Mapper the in-memory objects needn’t kNow even that there’s a database present; they need no sql interface code,and certainly no kNowledge of the database schema.

如何在关系数据库中存储数据通常与在内存中构造对象的方式不同.例如,一个对象将有一个包含其他对象的数组,而在数据库中,您的表将具有另一个表的外键.由于object-relational impedance mismatch,您在域对象和数据库之间使用中介层.这样,您可以在不影响另一方的情况下进化.

Single Responsibility Principle中更紧密地分离其自己层中的映射责任.您的对象不需要知道DB逻辑,反之亦然.这为您在编写代码时提供了更大的灵活性.

当您不想使用域模型时,通常不需要DataMapper.如果您的数据库表很简单,那么使用TableModule和TableDataGateway甚至只是ActiveRecord可能会更好.

对于其他各种模式,请参阅我的答案

> ORM/DAO/DataMapper/ActiveRecord/TableGateway differences?
> http://martinfowler.com/eaaCatalog/index.html

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...