DDD-Use Aggregation (Aggregate) to design class libraries

Source: Internet
Author: User

Openexpressapp uses the CSLA Library framework, the design of the class library can draw on the domain-driven design concept of DDD, this article introduces the concept of aggregation, understanding this concept can be clear management of the network between the class library, can reduce complexity of complex systems and improve maintainability.

Polymerization

A model will contain a large number of domain objects, regardless of how much is considered at design time, we will see many objects are associated with other objects, forming a complex network, if the design is not good, this network will bring poor maintainability and low performance.

Aggregation is a domain pattern that defines the ownership and boundaries of objects, using boundaries to separate internal and external objects, and a series of related object combinations that are considered for data change. Aggregation makes the model more compact by defining clear ownership and boundaries, avoids the emergence of an intricate network of objects (relationships), reduces unnecessary connections between objects, and links closely related objects to improve system management.

The aggregation class hides the usage of the collaboration class for the caller, and can be used to encapsulate the complex, intrusive, state-dependent requirements of the domain class.

Rules

Each aggregation has a root object, which is an entity

External objects can only access the root object, and must be navigated by the root object if you want to access the aggregate child objects

Root objects and child objects can hold references to any other aggregate root objects

When the root of the aggregation is established, all aggregates contain objects that are created and all invariants are hardened.

Maintain data consistency and enhance invariants

Other objects can only hold a reference to the root object, and cannot modify the aggregation child objects directly. If you want to change child objects, they can perform certain actions only through the root object.

The root object can change other objects, but this is the operation contained within the aggregation, and it is controllable

If the root is removed or removed from memory, all other objects within the aggregation will also be deleted because no other object holds any of them. When modifications to the root object indirectly affect other objects within the aggregation, the hardening invariant becomes simpler because the root will do the thing. If external objects can directly access internal objects and change them, it becomes difficult to manage the consistency and invariants of these objects

How external objects Reference internal objects

Navigating through the root object

When used temporarily, the root object can pass an internal temporary reference to an external object, but as a constraint, the external object cannot hold the reference until the operation completes. A simple implementation is to pass a copy of a value object to an external object. What happens on this object is no longer important, because it does not affect the consistency of aggregations in any way.

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.