• 什么是聚合根?


    原文链接:http://stackoverflow.com/questions/1958621/whats-an-aggregate-root

     回答一:

    In the context of the repository pattern, aggregate roots are the only objects your client code loads from the repository.

    The repository encapsulates access to child objects - from a caller's perspective it automatically loads them, either at the same time the root is loaded or when they're actually needed (as with lazy loading).

    For example, you might have an Order object which encapsulates operations on multiple LineItemobjects. Your client code would never load the LineItem objects directly, just the Order that contains them, which would be the aggregate root for that part of your domain.

    在仓储模式(repository pattern)的上下文中,聚合根(aggregate roots)是客户端代码唯一能从仓储(repository)中获取到的对象。

    仓储将对子对象的访问封装到了聚合根中——从调用者的角度来看它们是自动加载的,无论是和聚合根同时加载还是按需加载(lazyload)。

    例如一个包含多个LineItem对象的Order对象,客户端代码获取到的不是LineItem对象,而是作为这一部分业务的聚合根存在的Order对象。

    回答二:

    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.

    From Evans DDD:

    聚合是一组我们视为数据修改和访问的单元的关联对象。每个聚合都有一个聚合根和一个边界,边界定义了聚合包含哪些内容,而聚合根则是包含在聚合内的一个唯一的、特殊的实体。

    And:

    聚合根是唯一一个允许外部对象引用的聚合成员。

    这意味着聚合根是唯一能从仓储中获取到的对象。例如一个包含客户实体和地址实体的模型,我们永远不会直接访问地址实体,因为它离开关联的客户以后没有任何意义。所以我们可以说客户(实体)和地址(实体)组成了一个聚合,而客户就是聚合根。

  • 相关阅读:
    《设计模式》-原则二:里氏代换原则(LSP)
    设计模式从0开始
    net reactor加密源码保软件安全-net reactor使用教程
    python中import和from...import区别
    Python之import
    c#执行bat批处理文件,并通过线程将结果显示在控件中
    C#中双问号、双冒号等几个特殊关键字
    Eclipse debug高级技巧(转)
    Android从零开始--安装
    以另一个用户来运行程序
  • 原文地址:https://www.cnblogs.com/iamppz/p/3968708.html
Copyright © 2020-2023  润新知