The value type is not identified and only records other class values. All attributes are read-only and can only be used to create new objects.
Design of Value Object
Including sharing and replication. The flyweight (Meta) mode enables shared value object.
Sharing and replication
Use sharing in the following cases
1) Saving database space or reducing the number of objects is a key requirement
2) When communication overhead is low (central server)
3) when the shared object is strictly limited to immutable
If the user has an object: the contact address, and the order has a user object, and you need to write down the address to which the user sent the order, the ID of the contact address is marked, so the address becomes an entity at this time.
In short, objects and value objects are converted in different projects (or even different stages of the same project). The basis for conversion is "requirements ".
Entity type and Value Type Definitions
Comparison features |
Entity type) |
Value Type) |
Whether there are attributes used to identify the object (if the primary key is a composite primary key, it may be multiple), and the attribute has its corresponding primary key in the database. |
Yes, and the attribute corresponding to the primary key in the class is used to identify the object. |
No, so the object itself does not have an attribute to identify the object (but this class may have an exclusive table, but the primary key in the table does not correspond to any attribute in the object .) |
Can it be referenced by more than one object? |
Yes. When referenced by other objects, they are associated in the database using foreign keys. Because they can be referenced by more than one object, they must have the attributes used for identification. |
No. |
Lifecycle |
Independent |
Depends on the dependent class |