Entity
Identity over time matters more than full structural equality.
DDD sharpens one of the most useful modeling distinctions in object-oriented design: some things matter because they have identity over time, while others matter only because of what they are. Orders are entities. Money and addresses are often value objects. The distinction changes equality, lifecycle, and behavior design.
If a shipping address is treated like an entity when it should be a value object, the model becomes awkward. If an order is treated like just a value bag when it has identity and lifecycle, the model becomes brittle. This distinction affects almost every important modeling decision.
An entity is defined by continuity and identity. A value object is defined by attributes and meaning. Value objects are often immutable and easier to reason about. Entities usually own lifecycle and state transitions over time.
DDD makes this distinction especially useful because rich domain models often improve when more concepts become value objects and fewer concepts are treated as generic entities by default.
Identity over time matters more than full structural equality.
Meaning comes from attributes, and immutability often improves safety.
The distinction clarifies invariants, equality, and ownership.
Order remains the same business object even as status changes. A Money amount or ShippingAddress is usually best treated as a value object because its meaning comes from the values it contains.
package org.javaomnibus.ecommerce.domain;
public record Money(java.math.BigDecimal amount, String currency) {}
public final class Order {
private final OrderId id;
private Money total;
public Order(OrderId id, Money total) {
this.id = id;
this.total = total;
}
public OrderId id() {
return id;
}
}