Overview

1 Data Oriented Programming

Data-oriented programming centers the design of software on the meaning and representation of data itself. By modeling “data as data” (values independent of behaviors), code becomes simpler, smaller, and clearer because semantics are expressed directly in types and structures rather than hidden behind incidental object state. Objects are not discarded; they’re repositioned as tools for boundaries, orchestration, and resource management, while data representation carries the domain meaning. The core move is to make the code describe itself so that illegal states become unrepresentable and the need for defensive logic diminishes.

The chapter illustrates this with two concrete progressions. First, replacing a vague String id with a UUID aligns the representation with intent, eliminating countless invalid states and the validation code they require. Second, a ScheduledTask example exposes how implicit state (e.g., scheduledAt, attempts) forces readers to infer semantics. Refactoring those states into explicit data types (such as RetryImmediately, ReattemptLater, Abandon under a RetryDecision) bakes domain meaning into the model, enabling semantic integrity, easier reasoning, and clearer usage everywhere (e.g., task.isAbandoned or checks against Abandon) while still integrating cleanly with object-oriented interfaces.

As models become explicit, program structure naturally orients around data: methods take and return domain-specific data (e.g., reschedule(FailedTask) -> RetryDecision), logic becomes expression-driven, and objects act like pipelines that vend and transform data. This style enhances readability and stability by making intent visible at the type and signature level. While the book leverages modern Java features (records, pattern matching, sealed types in Java 21), the principles apply back to Java 8 with conventions and libraries. The teaching approach uses small, realistic examples—often exploring the “wrong” path—to build intuition. The simple practice is: clarify what the data is, express that meaning directly in code, and let the benefits ripple outward through the system.

Objects and how they communicate is our focus during object-oriented design
The representation of our data is the primary focus during data oriented design
Being explicit about what a task can transition to after failing
Representing each decision as a piece of standalone data
Focusing on just the data makes us question our representation
clarifying what we’re talking about
Analyzing the data drives a deeper exploration of the domain
How data-oriented programs tend to be shaped

Summary

  • Data Oriented programming is about programming with data "as data"
  • Data is more than just a collection of values. It has an inherent meaning.
  • Modeling “data as data” lets us focus on capturing that meaning in isolation from other concerns
  • Before asking “what does it do?” data orientation starts a more bedrock question of “what is it?” We want to understand what these things in our domain are at a fundamental level
  • Data Orientation is not a replacement for object orientation, functional programming, or any other paradigm. We view all of them as useful tools.
  • The representations we choose for our data affects our programs as a whole.
  • Good representations eliminate the potential for bugs by making it impossible to create invalid data
  • Bad representations introduce problems which ripple outward through our codebase and force us to spend effort working around them
  • We can replace reasoning about what vague variable assignments mean by representing that meaning with a concrete data type
  • Focusing on the data inside of our objects, rather than just the interfaces, makes our objects as a whole more understandable
  • When we do a good job of modeling the data, the rest of the code will feel like it’s writing itself. We just have to follow where the data leads
  • Data-Oriented programs tend to be built around functions that take data as input and return new data as output
  • We’ll use Java 21 throughout the book (though, you can still follow along with Java 8)

FAQ

What is Data-Oriented Programming (DOP) in Java as described in this chapter?DOP organizes programs around the data they manage. You model data “as data” — plain values with precise representations — independent of classes’ behavior. This makes code smaller, simpler, and easier to understand because meaning is expressed directly in the data types.
Does Data-Oriented Programming mean abandoning objects?No. Objects remain valuable, especially for managing stateful resources and enforcing boundaries. The shift is about where and how much we use objects: let objects define boundaries and orchestration, while core domain meaning is captured as explicit data.
Why is data representation so critical?The representation communicates semantics. For example, using String for an id is ambiguous; switching to UUID encodes “what it is” in the type. Better representations eliminate illegal states, reduce defensive code, and make intent obvious to readers.
How does DOP reduce bugs and code size?By choosing types that only allow valid states, you remove entire classes of errors. Fewer “wrong” states means fewer checks, less validation glue, and fewer tests for those checks. The result is a smaller, simpler codebase that’s easier to reason about.
What does “semantic integrity” mean here?It’s the enforcement of domain meaning in code. Instead of spreading implicit interpretations (e.g., null means abandoned) across the codebase, DOP encodes meaning in explicit data types, preventing drift and misinterpretation over time.
How do I refactor implicit object state into explicit data?Identify the domain concepts hidden in fields and assignments, then model them as standalone data. In the chapter, attempts and scheduledAt become a RetryDecision with concrete variants like RetryImmediately, ReattemptLater, and Abandon. Call sites then work with explicit decisions instead of guessing from raw fields.
How does DOP influence method and API design?Methods tend to take data as input and return data as output, making intent visible at the signature. For example, static RetryDecision reschedule(FailedTask task) communicates far more than void reschedule(). Implementations become expression-oriented, often using pattern matching.
Is using instanceof acceptable in data-oriented code?While instanceof is often a smell in OO design, here it’s used over data variants to express explicit semantics (e.g., status instanceof Abandon). Because we’re treating values as data rather than polymorphic objects, different trade-offs apply. The book later justifies this pattern in detail.
How do DOP and OO complement each other?DOP clarifies meaning via data; OO provides boundaries and behavior. For example, store a RetryDecision in the object and expose a method like isAbandoned() that delegates to the data. Good data models naturally drive clean, expressive OO interfaces.
Which Java version is needed for the book’s approach?The book targets Java 21 (records, pattern matching, sealed types), but all ideas work on older JDKs. JDK 8 is the “bedrock” minimum: when newer tools aren’t available, you can use libraries, annotation processing, or conventions. The core is the data; tools just help.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$399.99
only $33.33 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Data-Oriented Programming in Java ebook for free
choose your plan

team

monthly
annual
$49.99
$399.99
only $33.33 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Data-Oriented Programming in Java ebook for free