- 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模型类吗?
请解释.
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
原文地址:https://www.jb51.cc/php/135469.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。