What is an aggregate root?

Source: Internet
Author: User

Each aggregation has a Root entity (aggregation Root, Aggregate Root). This Root entity is the subject of the domain concepts expressed by aggregation,When an external object needs to access the entity in the aggregation, it can only be accessed through the aggregation root, but cannot be accessed directly.. From a technical point of view, aggregation determines the scope of Attention to the object lifecycle, that is, when an object is created, the whole aggregation with its root needs to be created at the same time. When an object is persisted, you also need to persistently aggregate the entire data. For example, when recreating a "customer" object from an external persistence mechanism, you also need to assign the "Credit Card" you own to the "customer" entity (how to operate it, depends on your needs ). Don't pay attention to the lifecycle of aggregate objects. If you do, you need to consider whether your design is reasonable.

Domain models need to be divided into multiple aggregates Based on domain concepts. Each aggregation has an entity as the "aggregation root". In general, domain objects are created from nothing, andCRUD operations should all work on the aggregation root.Instead of a single entity. When your code needs to directly perform the CRUD operation on the aggregate internal entities, it indicates that your model design already has problems.

Another significance of aggregation is to define the scope of persistence. In other words, all objects in the aggregation are "both exist and none ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.