What's an Aggregate Root?

前端 未结 11 1573
臣服心动
臣服心动 2020-11-22 04:18

I\'m trying to get my head around how to properly use the repository pattern. The central concept of an Aggregate Root keeps coming up. When searching both the web and Stack

11条回答
  •  面向向阳花
    2020-11-22 04:32

    From Evans DDD:

    An AGGREGATE is a cluster of associated objects that we treat as a unit for the purpose of data changes. Each AGGREGATE has a root and a boundary. The boundary defines what is inside the AGGREGATE. The root is a single, specific ENTITY contained in the AGGREGATE.

    And:

    The root is the only member of the AGGREGATE that outside objects are allowed to hold references to[.]

    This means that aggregate roots are the only objects that can be loaded from a repository.

    An example is a model containing a Customer entity and an Address entity. We would never access an Address entity directly from the model as it does not make sense without the context of an associated Customer. So we could say that Customer and Address together form an aggregate and that Customer is an aggregate root.

提交回复
热议问题