liveBook · Manning

Chapter 2: Data, Identity, and Values

What you will learn in chapter 2 of Data-Oriented Programming in Java

Introduces the chapter’s plan to explore representing data as data in Java, including entities that change over time.

After this chapter you will be able to

Section by section

Introduction

Introduces the chapter’s plan to explore representing data as data in Java, including entities that change over time.

2.1 Identity is about continuity over time

The section explains identity as continuity across changing states, rather than a particular state or the Java mechanism used to track it.

Key terms: identity, state, object identity, values, data-oriented programming

2.2 Representing Values in Java

Defines values and explains how Java classes can represent them despite Java objects having identities.

Key terms: value, immutable state, identity, Value Classes, object identities, value objects, state, same state, same value, equivalent value object

2.2.1 Building complex values out of other values

This section argues that value classes can be as large and complex as the domain requires, despite object-oriented instincts to treat them as simple or “anemic.”

Key terms: value objects, value classes, object identity, anemic

2.2.2 Modeling Java collections as values

This section explains when Java collections can behave as values rather than identities, and why collection constructors can undermine that behavior.

Key terms: value object, identity object, Unmodifiable wrappers, equality, unmodifiable, Collections package, .of(), Arrays.asList(...), internal mutability

2.2.3 Things to watch out for when creating values

This section explains how mutable variables can undermine intended value semantics and how `final` helps make those semantics clear in Java.

Key terms: value, identity, mutable variable, final, value semantics, instance variables, data-oriented patterns

2.2.4 Mutability converts values back into identities

This section explains why a mutable reference anywhere inside a value object makes it behave like an identity, even when enclosed in an unmodifiable collection.

Key terms: value objects, mutable reference, identity, Unmodifiable

2.3 Data = values + meaning

The section explains how a value becomes data when it has domain meaning, and how representation communicates that meaning in code.

Key terms: values, data, semantics, semantics of the data, semantics of our code, domain, representation, integers, double, fidelity

2.3.1 What can data be?

The section broadens data from information about events to meaningful values that can represent actions, decisions, names, and even identities.

Key terms: data, value, meaning, decisions, actions, identity

2.4 Identity in the World of Data

The section shows that identity is continuity across a succession of values, not something that requires a particular Java object or in-place mutation.

Key terms: identity, succession of values, object identities, values, frames, timeline, mutation, side-effected

2.5 Programming with immutable data

The section shows how immutable data can represent change through successive values and compares two ways to write the operations that produce them.

Key terms: succession of values, current state, next state, stand-alone static method, value object, data in; data out, fluent-like APIs, chaining, domain behaviors

2.6 Modeling Data and Values with Records

The section introduces Java records as transparent, concise carriers of values whose meaning comes from their declared state rather than object identity.

Key terms: records, transparent carriers of values, information hiding, state description, effectively immutable, object identity, state, value objects

2.6.1 Compact Constructors

This section explains how record compact constructors reduce constructor boilerplate, enforce a data type’s invariants, and transform incoming arguments before assignment.

Key terms: Compact Constructor, record’s header, validation, invariants, semantics, transform, incoming arguments, mutable references

2.6.2 Things to watch out for with records (Part I): shallow immutability

This section explains how mutable collection references can undermine a record’s value semantics, and how copying and explicit types help preserve them.

Key terms: records, value-like, mutable reference, List, transformation in the constructor, copy, value semantics, mutability, wrapper types, ImmutableList

2.6.3 Things to watch out for with records (part II): nulls

This section explains why nulls undermine trustworthy data models and why explicit null checks in record constructors are a design tradeoff.

Key terms: null, optionality, data model, constructor validation, semantic validation, boilerplate

2.6.4 Some other niceties that come with records

This section shows how records make small, named data types easy to define, improving readability within methods and changing how related types can be laid out in files.

Key terms: local records, tuples, positional based data structures, records, one class per file, related data types

2.7 What to do if you’re on an older JDK

Older Java versions can still support data-oriented modeling through ordinary classes or annotation processors that reduce boilerplate.

Key terms: vanilla classes, records, boilerplate, annotation processor, Lombok, Immutables, byte code manipulation, source generation

2.8 Wrapping up

The section recaps identity, values, data, and the Java tools used to represent them.

Key terms: identity, values, data, semantics, domain, value classes, records, compact constructor

2.9 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 1: Data Oriented Programming Chapter 3: Encoding Semantics in the Type System →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.