encyclopegia.org

Value object

In computer science, a value object is a small object that represents an entity whose equality is not based on identity: i.e. two value objects are equal when they have the same value, not necessarily being the same object. Examples of value objects are objects representing an amount of money or a date range. Being small, one can have multiple copies of the same value object that represent the same entity: it is often simpler to create a new object rather than rely on a single instance and use references to it. Value objects should be immutable: this is required for the implicit contract that two value objects created equal, should remain equal. It is also useful for value objects to be immutable, as client code cannot put the value object in an invalid state or introduce buggy behaviour after instantiation. Value objects are among the building blocks of DDD.

In computer science, a value object is a small object that represents an entity whose equality is not based on identity: i.e. two value objects are equal when they have the same value, not necessarily being the same object. Examples of value objects are objects representing an amount of money or a date range. Being small, one can have multiple copies of the same value object that represent the same entity: it is often simpler to create a new object rather than rely on a single instance and use references to it. Value objects should be immutable: this is required for the implicit contract that two value objects created equal, should remain equal. It is also useful for value objects to be immutable, as client code cannot put the value object in an invalid state or introduce buggy behaviour after instantiation. Value objects are among the building blocks of DDD. ==Implementation== Due to the nuances of various object-oriented programming languages, each has its own methods and patterns for implementing and using value objects. Override the method to ensure the object is compared using business logic Operator overload the default behavior of and to use the method. Override the method and ensure that the hash is same for the objects who have same equality. Make the class immutable by removing any property setters and only passing member values through the constructors. Example: public record StreetAddress(string Street, string City); or with a more verbose syntax: public class StreetAddress { public StreetAddress(string street, string city) { Street = street; City = city; } public string Street { get; } public string City { get; } } ===C++=== In C++, a value object can be built by overloading the assignment operator and using appropriate constness constraints on the fields (that will be evaluated once by the initializer list of the constructor) and on the methods of the class. However, if the fields themselves are declared const (rather than use non-const fields while only exposing "getter" accessors), then it won't be possible to fully overwrite such a value object with another ( ). ===Python=== Python has data classes which provides equality testing and can be made immutable using the frozen parameter. from dataclasses import dataclass @dataclass(frozen=True) class StreetAddress: """Represents a street address.""" street: str city: str ===Java=== Value objects are available since Java 14, as data records Unlike C# and C++, Java has no support for custom value types at the language level. Every custom type is a reference type, and therefore has identity and reference semantics, though extending support for custom value types is being considered. Java programmers therefore emulate value objects by creating immutable objects, because if the state of an object does not change, passing references is semantically equivalent to copying value objects. A class can be made immutable by declaring all attributes blank final, and declaring all attributes to be of immutable type (such as , , or any other type declared in accordance with these rules), not of mutable type such an or even a . They should also define equals and hashCode to compare values rather than references. The term "VALJO" (VALue Java Object) has been coined to refer to the stricter set of rules necessary for a correctly defined immutable value object. public class StreetAddress { public final String street; public final String city; public StreetAddress(String street, String city) { this.street = street; this.city = city; } public boolean equals(StreetAddress that) { return getClass()==that.getClass() && street==that.street && city==that.city; } public int hashCode() { return Objects.hash(street, city); } } Java 14 : public record StreetAddress (String street, String city) {} ===Kotlin=== data class StreetAddress(val street: String, val city: String) In Kotlin, any class may have a constructor shortcut before the class body (if there is a body at all), which doubles as a declaration of fields and the assignation to those fields. Adding the `data` keyword causes the generation of implementations of `equals` and `hashCode` and the like. ===Ruby=== Ruby has immutable value object support via the Data.define class (introduced in Ruby 3.2), which automatically provides equality, hashing, and immutability. StreetAddress = Data.define(:street, :city) ==See also== Data transfer object Domain-driven design Value semantics ==References==

References

No reference rows published for this article.

Cite this article

MLA

"Value object." encyclopegia.org, 2026, https://encyclopegia.org/wiki/value-object. Accessed 24 November 2026.

Chicago

"Value object." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/value-object.

APA

encyclopegia.org. (2026). Value object. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/value-object

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

History of Leeds United F.C.

enwiki · references available

Ebba Koch

enwiki · references available

Fethullah Gülen

enwiki · references available

Gothic Kabbalah

enwiki · references available

Mark Ford (footballer)

enwiki · references available

Tim Stapleton

enwiki · references available

Battle of Saniyy

enwiki · references available

Battle of Zumail

enwiki · references available

Battle of Firaz

enwiki · references available

Germany at the 1952 Summer Olympics

enwiki · references available

Phil Eastwood

enwiki · references available

New York Buzz

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1359547997 · 0.5 · snapshot enwiki-001359547997

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.