Experiences in value object judgment

Source: Internet
Author: User
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

 

 

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.