Introduction to domain-driven design concepts

Source: Internet
Author: User

Entity)

A domain object with a unique identifier. Identify different entities. The entity has uniqueness.

Note: A domain is a specific problem domain, such as the ordering domain. It is a model used to describe things.

Value Object)

Unlike an object, a value object is not identified. You do not need to maintain the identity and status of the value object. It is very easy to create and discard value objects. In most cases, a value object only contains data and does not contain behavior. The value object is preferably immutable. That is to say, a value object is created using a constructor. All attributes are read-only and do not need to maintain the status of the value object. Unchangeable value objects can be shared.

Criteria for distinguishing objects between objects and values: identifies objects that are unique and are entities.

Aggregate)

Domain Model cohesion is achieved by defining clear relations and boundaries between objects. It also avoids the formation of complex and difficult-to-maintain object network relationships. Aggregation defines a group of related sets with cohesion. We regard aggregation as a unit of work.

Aggregation features:

1. Each aggregation has a root (aggregation root) and a boundary. The boundary defines the entities or value objects in an aggregation. The root is an entity in the aggregation.

2. The aggregate root can reference other aggregate roots. Generally, they are associated by ID (ID), and objects in the aggregate can reference each other. An aggregate root is a medium for external access to aggregate internal objects. In other words, if an aggregate external access to an aggregate internal object, the aggregation root must be used to start navigation and direct access to the aggregate internal objects is not allowed.

3. the identity of the aggregation root is the identity of the whole aggregation.

4. Aggregation is a unit. We rebuild aggregation from the database or other storage (read reconstruction from the corresponding domain, and create in the new domain) and read the entire aggregation, instead, you cannot directly query a non-root object in the aggregation. When deleting an aggregate root, all related objects in the aggregate must be deleted at the same time. Aggregation is a complete and integral whole.

Aggregate root)

An entity in aggregation.

Difference aggregation root:

1. It has the meaning of independent existence, that is, it makes sense only when it does not depend on the existence of other objects.

2. It can be accessed independently or it must be obtained through the navigation of an object.

Service)

The service here is not unrelated to soa. Sometimes when designing a domain model, some behaviors are not suitable for any class. We usually create a service class to maintain these behaviors. The service class has no internal status and can be implemented simply as an interface that provides operations. The service usually coordinates the work of one or more domain objects. Note that services can be placed at the application layer, domain layer, and basic service layer.

Application Service)

Services in the application layer are usually distributed to services in other layers. In most cases, services in the application layer are process-oriented.

Domain Service)

Processes the interaction of value object entities in the domain.

Basic layer service ()

Services that are not relevant to the business, such as the mail Notification Service.

Warehousing (Repository)

Warehousing is responsible for persisting domain objects to databases or other storage media, or recreating domain objects from databases when domain objects are required. The lower layer of the warehouse is the database, and the upper layer is the service. From a broader perspective, we often get one or more objects from a similar set place (database) according to a certain condition like a set. Add or remove objects in this collection. Warehousing provides similar set interfaces to help us manage objects. Or, to put it bluntly, warehousing is the performance of data in the database in the memory. Generally, warehousing consists of two parts: the definition part (Interface) of warehousing and the implementation part (interface implementation class) of warehousing. Generally, the definition part of warehousing is stored in the domain model, the implementation part is stored in the basic service layer. Although the storage can manage objects in the memory like a collection, the storage is not responsible for the processing Of things, and the general processing Of things is handed over to the Unit Of work)

Factory)

You can use constructors to create simple domain objects. The factory is used to encapsulate what is needed to create a complex object, especially aggregation.

Domain Layer

Domain service object composition Domain Layer

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.