DDD - Persistence Model and Domain Model

后端 未结 3 800
野性不改
野性不改 2020-12-12 10:26

I am trying to learn domain-driven design (DDD), and I think I got the basic idea. But there is something confusing me.

In DDD, are the persistence model and domain

3条回答
  •  甜味超标
    2020-12-12 10:54

    In DDD, are persistence model and domain model different things?

    Yes, but that does not necessarily imply a different set of classes to explicitly represent the persistence model.

    If using a relational database for persistence an ORM such as NHibernate can take care of representing the persistence model through mappings to domain classes. In this case there are no explicit persistence model classes. The success of this approach depends on that mapping capabilities of the ORM. NHibernate, for example, can support an intermediate mapping class through component mappings. This allows the use of an explicit persistence model class when the need arises.

    If using a document database for persistence, there is usually even less need for a persistence model since the domain model only needs to be serializable in order to be persisted.

    Therefore, use an explicit persistence model class when there is a complex mapping that cannot be attained with ORM mappings to the domain model. The difference between the domain model and the persistence model remains regardless of implementation.

提交回复
热议问题