State is the data describing an object or entity’s current condition. In Java, its meaning often hides behind combinations of fields: one flag set, another unset, or several fields changed together. That implicit encoding makes invariants difficult to see and maintenance difficult for anyone who did not write the code. section 1.3
State is not the same as identity. A variable or object provides a place with continuity over time, while its stored values change. Data-oriented design can instead represent identity through values and model change as a succession of states. section 2.1 section 2.5
A useful state model makes these distinctions explicit:
- Treat a value as a single immutable state with no semantically meaningful identity; equal state means equal value. section 2.2
- Represent change by passing the current state into a function and returning the next state rather than mutating the existing data. section 2.5
- Model behavior as a discrete transformation between named data states, even when the behavior resembles an external action such as an API call. section 5.3
- Use state coverage in tests to explore combinations and rarely exercised cases, while avoiding hard-coded values that create hidden coupling. section 11.8
Moving a ball without mutation
A Ball begins at position (0, 0) with velocity (1, 0). Applying step for one second returns a new Ball at (1, 0); applying it again returns (2, 0). The earlier states remain available as data. section 2.5
Listing 2.27 Computing the next state from the current one
import static com.dop.chapter02.step float simulatedDuration = 1.0f; Ball ball = new Ball(new Point(0.0, 0.0), new Vector(1.0, 0.0)); #A Ball updated = step(ball, simulatedDuration); // [out] Ball(position=(1.0, 0.0), vector=(1.0, 0.0)); Ball updatedAgain = step(updated, simulatedDuration); // [out] Ball(position=(2.0, 0.0), vector=(1.0, 0.0));
Trace how a transition function computes each next Ball state from the preceding one. section 2.5



















































