Browse OOP reference
Modelling and persistence

What are value objects?

On this page

A value object represents something whose attributes determine its meaning. Two Money values with the same currency and minor-unit amount can be interchangeable. Immutability makes sharing safe. Decide on rounding and currency compatibility before exposing arithmetic or equality.

Worked example

Python
from dataclasses import dataclass

@dataclass(frozen=True)
class Money:
    currency: str
    cents: int

prices = {Money("EUR", 125), Money("EUR", 125)}
assert len(prices) == 1
assert Money("USD", 125) not in prices

Python data classes

Explore class relationships in the OOP Playground

What is an object?What is object identity?What is delegation?

All OOP questions

Search ObjectFAQ