Data as data means representing domain information as values that describe themselves, rather than leaving its meaning implicit in private object state and opaque methods. A type named Degrees says more than a bare Double; further types can remove ambiguity until state, rules, and domain models are explicit, immutable, well-typed data. section 1.0 section 1.1
This does not discard objects. Objects remain useful for boundaries and encapsulated state, while openly modeled data makes representation carry more of the program’s meaning. Making data stand on its own forces questions that hidden state can postpone: what does it mean, which distinctions matter, and how should each distinction be represented? section 1.1 section 1.4
Represent data as data by making its semantics visible:
- Give meaningful concepts their own types, including small distinctions such as Angle and Degrees. section 1.0
- Model distinct states separately when they carry different concerns, such as failed, scheduled, completed, or running tasks. section 1.4
- Prefer operations that accept domain data and return domain data, so signatures reveal their purpose and result. section 1.4
- Use immutable values for information, decisions, actions, and even identity over time by representing change as a succession of values. section 2.3.1 section 2.9
Make rescheduling visible in the signature
A void reschedule() method on ScheduledTask hides both its input and outcome. A transformation such as static RetryDecision reschedule(FailedTask task) exposes that rescheduling applies to a failed task and produces a retry decision. Its implementation can pattern-match the task and return RetryImmediately, ReattemptLater, or Abandoned rather than mutating hidden status. section 1.4
Data need not be limited to reports or stored facts. A daily electricity reading and a sale are data, but so are a future retry action and an Abandon decision whose meaning is conveyed entirely by its type. Values become data when they are given domain meaning or context. section 2.3.1 section 2.9
Listing 1.14 Which tells you more about what the method does?
public void reschedule(){} #A
// versus
public static RetryDecision reschedule(FailedTask task) { #B
// ...
} Compare a command-shaped method with a data-shaped transformation to see how inputs and outcomes become part of the visible design. section 1.4
