SOLID & Design Patterns Interview Question #70
What is a Value Object?
Advanced Patterns, CQRS & Domain-Driven Design Fundamentals Mid-Level Intermediate
Quick Interview Answer
A Value Object represents a concept defined by its values rather than a unique identity. Value objects are usually immutable and compare structurally by their component values.
Detailed Explanation
A Value Object represents a concept defined by its values rather than a unique identity. Value objects are usually immutable and compare structurally by their component values.
Examples include Money, Address, DateRange, or Coordinates when identity is not meaningful. Value objects can encapsulate validation and domain behavior instead of passing primitive values throughout the application.
Code Example
public sealed record Money(
decimal Amount,
string Currency);
var a = new Money(100m, "USD");
var b = new Money(100m, "USD");
// Records provide value-style equality.
Console.WriteLine(a == b); // True