Definition

Ward Cunningham defines a Value Object as:

A measure or description of something. Examples of Value Objects are things like numbers, dates, monies and strings. Usually, they are small Objects which are used quite widely. Their identity is based on their state rather than on their Object identity. This way, you can have multiple copies of the same conceptual Value Object. Every $5 note has its own identity (thanks to its serial number), but the cash economy relies on every $5 note having the same Value as every other $5 note.

Martin Fowler defines a Value Object as:

A small Object such as a Money or the date range object. Their key property is that they follow value semantics rather than reference semantics. You can usually tell them because their notion of equality isn't based on identity, instead two Value Objects are equal if all their fields are equal. Although all fields are equal, you don't need to compare all fields if a subset is unique — for example currency codes for currency objects are enough to test equality. A general heuristic is that Value Objects should be entirely immutable. If you want to change a Value Object you should replace the object with a new one and not be allowed to update the values of the value object itself — updatable value objects lead to aliasing problems.

Examples of Value Objects are numbers, text strings, dates, times, a person's full name (composed of first name, middle name, last name, and title), currencies, colors, phone numbers, and postal addresses.

Exercise
Try to locate more examples of potential Value Objects in your current Domain.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.160.43