2

我已经阅读了很多关于一些 DataMapper 模式的内容。

只要我理解,DataMapper 就应该将表单模型对象映射到实体对象。所以被用作某种适配器。

我理解正确吗?

4

2 回答 2

4

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.

于 2012-05-02T11:03:29.117 回答
2

elnur is right about DataMapper, if you want to know about mapping forms to objects, you can use what symfony calls a DataTransformer.

于 2012-05-22T20:57:18.137 回答