2016-01-28 23:33:46 +09:00
|
|
|
---
|
|
|
|
layout: pattern
|
|
|
|
title: Value Object
|
|
|
|
folder: value-object
|
|
|
|
permalink: /patterns/value-object/
|
|
|
|
categories: Creational
|
2021-05-19 10:49:05 -06:00
|
|
|
language: en
|
2016-01-28 23:33:46 +09:00
|
|
|
tags:
|
2019-12-13 21:09:28 +02:00
|
|
|
- Instantiation
|
2016-01-28 23:33:46 +09:00
|
|
|
---
|
|
|
|
|
|
|
|
## Intent
|
|
|
|
Provide objects which follow value semantics rather than reference semantics.
|
|
|
|
This means value objects' equality are not based on identity. Two value objects are
|
|
|
|
equal when they have the same value, not necessarily being the same object.
|
|
|
|
|
2019-12-07 20:01:13 +02:00
|
|
|
## Class diagram
|
2016-01-28 23:33:46 +09:00
|
|
|

|
|
|
|
|
|
|
|
## Applicability
|
|
|
|
Use the Value Object when
|
|
|
|
|
2019-12-13 21:09:28 +02:00
|
|
|
* You need to measure the objects' equality based on the objects' value
|
2016-01-28 23:33:46 +09:00
|
|
|
|
|
|
|
## Real world examples
|
|
|
|
|
2016-01-29 00:53:27 +09:00
|
|
|
* [java.util.Optional](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html)
|
|
|
|
* [java.time.LocalDate](https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html)
|
2016-01-28 23:33:46 +09:00
|
|
|
* [joda-time, money, beans](http://www.joda.org/)
|
|
|
|
|
|
|
|
## Credits
|
|
|
|
|
|
|
|
* [Patterns of Enterprise Application Architecture](http://www.martinfowler.com/books/eaa.html)
|
|
|
|
* [VALJOs - Value Java Objects : Stephen Colebourne's blog](http://blog.joda.org/2014/03/valjos-value-java-objects.html)
|
|
|
|
* [Value Object : Wikipedia](https://en.wikipedia.org/wiki/Value_object)
|
2020-07-07 20:05:35 +03:00
|
|
|
* [J2EE Design Patterns](https://www.amazon.com/gp/product/0596004273/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596004273&linkCode=as2&tag=javadesignpat-20&linkId=f27d2644fbe5026ea448791a8ad09c94)
|