liveBook · Manning

Data as data

As explained in Data-Oriented Programming in Java

Data as data is the representation of information as ordinary, openly accessible values rather than as hidden private object state.

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

How Data-Oriented Programming in Java covers it

How deep it goes
Develops representation through semantic types, state modeling, transformations, values, identity, and records.
Examples
Uses task rescheduling, electricity usage, sales, retry actions, and an Abandon decision.
What it assumes
Assumes intermediate Java while teaching value-based modeling of static information, identity, and change.
What you can do after
Evaluate/understand domain models by reading their types, values, and transformation signatures.
How it connects
Connects value objects, identity, immutability, records, sealed classes, and pattern matching.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming in Java. The section links point to the parts of the book it draws on.