我已经阅读了很多关于一些 DataMapper 模式的内容。
只要我理解,DataMapper 就应该将表单模型对象映射到实体对象。所以被用作某种适配器。
我理解正确吗?
我已经阅读了很多关于一些 DataMapper 模式的内容。
只要我理解,DataMapper 就应该将表单模型对象映射到实体对象。所以被用作某种适配器。
我理解正确吗?
No, Data Mapper is about mapping objects to the database — it has nothing to do with forms in any way.
The main advantage of the Data Mapper pattern is that you can evolve both your object model and the database schema independently — without bending one to another. In contrast, with Active Record you have to bend one of them — usually good database design is sacrificed to please the object model.
Doctrine 1.x was an implementation of something between Active Record and Data Mapper; Doctrine 2.x is a pure Data Mapper implementation.
elnur is right about DataMapper, if you want to know about mapping forms to objects, you can use what symfony calls a DataTransformer.