1 Data Oriented Programming
Large software systems are increasingly difficult to maintain because code changes quickly, AI can generate more code than people can review, and the real challenge is not just writing code but making sure it expresses the right domain meaning. The chapter argues that no code-focused paradigm alone can solve this, and that the better path is to shift attention toward the data a program manages. Data is presented as more flexible than code: it can be analyzed, transformed, and reinterpreted as requirements evolve.
Data-oriented programming in Java is defined here as modeling data directly in the type system so its meaning is explicit, precise, and immutable. A simple example shows how replacing an ambiguous string identifier with a UUID immediately removes invalid states and makes the code describe the domain more accurately. The same principle is then applied to a task-retry example, where implicit field assignments are hard to interpret, but explicit data types such as RetryImmediately, ReattemptLater, and Abandoned clearly communicate the possible outcomes and eliminate guesswork.
The chapter also shows that better data modeling improves the rest of the program: methods become easier to understand, state is less ambiguous, and interfaces can become more descriptive. Instead of hiding meaning behind nulls or overloaded fields, the code can expose domain concepts directly, while still using objects where they help. The overall message is that orienting around data naturally leads to clearer designs, simpler reasoning, and code whose structure follows from the model itself, with performance concerns treated as something to measure rather than assume.
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
Summary
- Data Oriented programming focuses on representing data "as data"
- Data Orientation does not replace object orientation. The two work together
- In OOP, the interfaces between objects are primarily where we improve designs.
- In DOP, the representation of data is where we improve designs
- While OOP primarily asks “what does it do?”, DOP asks “what is it?”
- To quote Fred Brooks, “data is the essence of programming”
- The types we pick to represent data have a giant effect on our programs
- The wrong data representation allows illegal states to exists.
- The right data representation makes illegal states impossible to express
- A lot of what makes reading code hard is understanding the original author’s intentions
- DOP gets rid of “If X is set then it means…, but if Y is set then …” code ambiguities
- Use concrete data types to represent the meaning behind variable assignments
- Focusing on data leads to “Aha!” moments that deepen your understanding of a domain
- instanceOf is perfectly fine when used with data. The object rules do not apply
- Combining DOP with OOP makes your objects more descriptive and easier to understand
- Code naturally begins to “orient” around a good data model.
- Objects emerge around data in a way that feels inevitable.
- Good data models extends to how we design methods
- void, zero argument methods are an informational black hole.
- Make methods show what they do by using descriptive inputs and return types
- Each chapter in this book will work through a unique example
- All examples in this book are pulled from the real world. You’ll get to see all my mistakes
- We’ll use features from the latest JDKs throughout the book, but you can still follow along with Java 8
FAQ
What is data-oriented programming in Java?
Data-oriented programming (DOP) is an approach that focuses on representing the domain clearly as data in Java’s type system. Instead of centering code and behavior, it emphasizes modeling state, business rules, and domain concepts as immutable, well-typed data so the program becomes easier to understand and maintain.
How is data-oriented programming different from object-oriented programming?
DOP does not reject objects or object-oriented programming. Instead, it treats objects as one tool among many. The main difference is that DOP puts the emphasis on data representation and semantics, while object-oriented programming often centers on encapsulation and behavior. In DOP, objects are used where they help, but data is made as explicit and descriptive as possible.
Why does representation matter so much in data-oriented programming?
Representation is critical because it determines what the code communicates and what states are allowed. A good representation makes the domain obvious and prevents invalid states. A poor representation creates ambiguity, forces defensive programming, and spreads hidden meaning throughout the codebase.
Why is String id considered a weak representation in the chapter’s example?
Because a plain String does not tell us what kind of identifier it is or what values are valid. If the domain actually requires a UUID, then String id allows many incorrect values and hides the real semantics. Replacing it with UUID id makes the code explicit and self-describing.
What problem does a better type like UUID solve in the example?
It removes ambiguity and illegal states. Once the code uses UUID instead of String, the program can only represent valid UUID values. That means fewer checks, fewer bugs, and less defensive code.
What is meant by “semantic integrity” in the chapter?
Semantic integrity means that the meaning of the data is encoded clearly and consistently in the code. When meaning is only implicit, different parts of the program can interpret the same values differently, leading to semantic drift and bugs. Explicit data modeling keeps the meaning aligned across the codebase.
Why does the chapter refactor ScheduledTask into explicit data types like RetryImmediately and Abandoned?
Because the original fields only hinted at what they meant. By turning those hidden states into explicit data types, the code directly expresses the possible outcomes of a failed task. That makes the domain easier to understand and the logic easier to reason about.
Can data-oriented programming still use objects?
Yes. The chapter explicitly says DOP uses objects, object orientation, imperative programming, and anything else with the right tradeoffs. The key is that all of these are used in service of better data modeling, not as the primary focus themselves.
How does data-oriented programming affect method design?
It nudges methods to take data in and return data out in a clear, expressive way. Instead of imperative methods that hide meaning behind assignments and side effects, DOP encourages methods whose signatures and return types make their purpose obvious.
Does data-oriented programming require the newest Java version?
No. The book uses Java 25, but the ideas work on older versions too. The chapter says the core ideas are compatible with JDK 8, and newer language features are just helpful tools rather than requirements.
Data-Oriented Programming in Java ebook for free