DDD and MVC: Difference between 'Model' and 'Entity'

后端 未结 5 693
夕颜
夕颜 2020-12-12 11:27

I\'m seriously confused about the concept of the \'Model\' in MVC. Most frameworks that exist today put the Model between the Controller and the database, and the Model alm

5条回答
  •  离开以前
    2020-12-12 11:56

    The "model" in your application is the bit which holds your data. The "entity" in domain-driven design is, if I remember correctly, a model with an identity. That is to say, an entity is a model which usually corresponds directly to a "physical" element in a database or file. I believe DDD defines two types of models, one being the entity, the other being the value, which is just a model without and identity.

    The Repository pattern is just a type of indexed collection of models/entities. So for instance if your code wants order #13, it will first ask the repository for it, and if it can't get it from there, it will go and fetch it from wherever. It's basically a level 1 cache if you will. There is no difference in how it acts with a model, and how it acts with an entity, but since the idea of a repository is to be able to fetch models using their IDs, in terms of DDD, only entities would be allowed into the repository.

提交回复
热议问题