Entity, the value of the object, the polymerization

definition:

Entities not only need to know what it is, but also know what it is, the value of the object only care what it is.

Entity: Many objects are not defined by their properties, but through a series of continuity and identity defined fundamentally. As long as an object in the life cycle to maintain the continuity and is independent of its properties (even though these attributes are very important to the users of the system), then it is an entity.

Value of the object: When you only care about the properties of an object, the object will be used as a value object. To add meaningful attributes, and give it the appropriate behavior. We need to value objects as immutable objects, do not want it any identity, should also be avoided as the same entity object complexity.

For entities, their core is defined by a unique identifier, rather than through the attribute definition. Even with identical properties may be different object. Meanwhile entity itself by state entities rigorous life cycle, the entity itself will be reflected in the relevant business practices, business practices will be affected and change entity properties or state.

Value stateless object itself, immutable, and not to assign a specific identification. He has no life cycle, it does not produce independent behavior.

For chestnut:

1, the device is powered by SN identification number, the phone is an entity. Phone accessories under such a scenario is the value of the object.

2, stadium seat, have a seat number on the ticket, seat number can uniquely identify the most seats is the entity. However, if the ticket is not the seat number, first do first, no seat seat number, only the number, take a little one, this time the seat is the value of the object.

Value of the object using the object:

Use the same value object allows us to do less assume responsibility.

Value objects are used to measure and describe things, DDD recommended to make use of the value of the object is modeled rather than solid objects, because the value of the object is very easy to create, test, use, optimization and maintenance.

Value of the object characteristics:

1, which depicts a thing or measure the field.

2, it can be used as invariants.

3, it can be related to the properties of the soil lever into one overall concept.

4, when the measurement changes and described, the object can be replaced with another value.

5, it can be compared, and otherwise equal values ​​objects

6, it will not cause side effects collaborators

Minimize integration:

DDD project, there are typically multiple bounded context, this means that we need to find a way to integrate these contexts. When the concept of context model context flows downstream from the upstream, to make use of the object represents the value of these concepts. This minimizes the number reaches the number integration properties, i.e., can be minimized models for the downstream management responsibilities. Inconvenient to use the value of the object allows us to do less assume responsibility.

 

 

      

Guess you like

Origin www.cnblogs.com/avalon-merlin/p/11266408.html