Standalone conceptConceptChapter I · Domain · Building block 9 of 18

Entity

Entities represent business objects that remain recognisable through state changes.

  1. IdentityThe order identifier connects its lifecycle.
  2. StateAttributes may change according to business rules.
  3. ComparisonMatching fields do not establish a shared identity.

Context

Why this is important

An order changes status. Its identity connects those states into one business transaction. Two orders with identical items remain two separate transactions.

Identity, lifecycle and behavior within a domain model.

At a glance · Identity persists

States change along the same identity.
Shop example · Equality test

Same order, different state

Follow B-1042 from creation to confirmation. Then compare B-1042 with a hypothetical second order, B-1043: identical items do not make them the same order.

This is how you read the picture

  1. Identity B-1042 stays the same on both sides.
  2. State The status changes from created to confirmed.
  3. Comparison B-1043 remains a different order despite having the same items.

Order

  • Order IDB-1042 (comparison field)
  • StatusCreated
  • Items2 mugs

Order

  • Order IDB-1042 (comparison field)
  • StatusConfirmed
  • Items2 mugs

same orderComparison of Identifier. The identifier is the same. The status may change in the life cycle, the order remains the same.

Choose a pair. The highlighted order identifier determines identity; underlined values show differences.

A monetary value needs a different comparison: amount and currency together.Explore value equality

One transaction over time

  1. 01

    B-1042 · created

    The order receives its identity and contains two mugs.

  2. 02

    Payment authorised

    Correlation links the payment response to order B-1042.

  3. 03

    B-1042 · confirmed

    The order status is updated. Its identity is preserved.

This state sequence is simplified. Rules in the order module determine which transitions are allowed.

Benefits & limitations

Helps if:

  • The object changes state while the business recognises it as the same thing.
  • Relationships and history depend on a stable identity.

Boundaries

  • A database key is a business identity only when the model uses it as such.
  • Identity alone protects no invariants; that requires a responsible aggregate and valid operations.

In practice

  1. Identify how domain experts recognise an instance despite changing attributes. Validate its identifier and lifecycle together, and check whether equal-looking numbers really denote the same thing.
  2. Define permitted state transitions and place the Entity within an appropriate consistency boundary. Check whether relationships, history and business decisions depend on the same identity.
  3. Compare two objects with equal attributes but different identifiers. Document whether they remain distinct in business terms and which rules make that distinction visible in the model.
Read the detailed explanation

Identity is defined within its model context. It may be a business number, composite key or technical identifier if the context uses it as a durable identifier. Equal attributes do not imply the same entity.

Entity behavior keeps state changes valid in business terms. Aggregates place entities within a consistency boundary; an entity outside an aggregate is not automatically an independent transaction boundary.

Entities are managed within a consistency boundary such as an Aggregate; value-based data is represented by a Value Object.

Check your understanding

Test yourself in three stages

  1. ReadingCheck in the picture

    Which property remains stable for order B-1042?

    View the solution with justification

    Its order identity.

  2. ApplyingTransferred to a new situation

    Two orders have the same fields but different numbers. Same or different?

    View the solution with justification

    Different entities if the order number defines their identity.

  3. EvaluateWeighing an alternative

    Why is a database ID alone insufficient for the modeling decision?

    View the solution with justification

    The model must define whether and how that identifier expresses business identity.

Continue on the learning path

Next in Domain Modelling & DDD: Aggregate.

18 Building blocks

Continue withAggregate