liveBook · Manning

What you will learn in Data-Oriented Programming in Java

by Chris Kiehl · Manning Early Access Program (MEAP)

Chapter by chapter

Chapter 1: Data Oriented Programming

The introduction defines the book’s data-oriented programming approach: represent domain meaning as well-typed, immutable data rather than relying on code alone to convey it.

1.1 Objects in a Data Oriented World · 1.2 The soul of data-oriented programming in a single line · 1.3 Show me your data, and the rest will be obvious · 1.3.1 Analyzing ambiguous OOP code · 1.3.2 Representing data “as data” · 1.4 Orienting around data · 1.5 Which version of Java do I need? · 1.6 How does this book teach? · 1.7 Summary

What you learn in chapter 1 →

Chapter 2: Data, Identity, and Values

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 · 2.2 Representing Values in Java · 2.2.1 Building complex values out of other values · 2.2.2 Modeling Java collections as values · 2.2.3 Things to watch out for when creating values · 2.2.4 Mutability converts values back into identities · 2.3 Data = values + meaning · 2.3.1 What can data be? · 2.4 Identity in the World of Data · 2.5 Programming with immutable data · 2.6 Modeling Data and Values with Records · 2.6.1 Compact Constructors · 2.6.2 Things to watch out for with records (Part I): shallow immutability · 2.6.3 Things to watch out for with records (part II): nulls · 2.6.4 Some other niceties that come with records · 2.7 What to do if you’re on an older JDK · 2.8 Wrapping up · 2.9 Summary

What you learn in chapter 2 →

Chapter 3: Encoding Semantics in the Type System

The chapter introduction argues that understanding what data means is a foundation for building reliable systems before representing that meaning in code.

3.1 “What does it mean?” · 3.1.1 Discovering more about your domain · 3.1.2 The importance of understanding meaning · 3.2 Capturing semantics in code · 3.2.1 Detailed documentation and better variable names are not enough · 3.2.2 Enforce invariants during construction · 3.2.3 Types denote sets of values · 3.3 Using the type system as a design tool · 3.3.1 Balancing type specificity with abstraction · 3.3.2 Scoping numeric types to specific ranges · 3.3.3 Beware the String · 3.4 Is all this effort worth it? · 3.4.1 Do types only catch low hanging fruit? · 3.5 What about performance? · 3.6 Wrapping Up · 3.7 Summary

What you learn in chapter 3 →

Chapter 4: Domain Modeling with Algebraic Data Types

The chapter introduces an iterative design approach that focuses on domain data and its meaning before operational or system-level concerns.

4.1 Starting from Requirements · 4.1.1 The Humble Checklist · 4.1.2 Firming up loose requirements · 4.1.3 Translating into a model · 4.1.4 New Requirements: Keeping Track of Who Did What · 4.1.5 Increasing complexity: another requirements change · 4.1.6 Beware of refactoring the code, rather than its meaning · 4.2 Records are tools for modelling “AND” · 4.2.1 Designing consciously with AND · 4.3 Modeling “one of” relationships with OR · 4.3.1 Interfaces are data types · 4.4 Some data models should be closed to extension · 4.5 Representing Sealed Families of Data · 4.6 Algebraic Data Types · 4.6.1 Product Types · 4.6.2 Sum Types · 4.6.3 What’s the point of knowing this stuff? · 4.6.4 Refactoring domain models algebraically · 4.7 What to do if you you're on older versions of Java · 4.8 Wrapping Up · 4.9 Summary

What you learn in chapter 4 →

Chapter 5: Modelling Domain Behaviors

Introduces the chapter’s plan to apply data-oriented modeling to a complex feature within an existing application.

5.1 "Encouraging timely payments" · 5.1.1 Invoicing (briefly) · 5.1.2 The Legacy System! · 5.1.3 A bunch of prior decisions designed around “free" · 5.2 Modeling domain behaviors around existing code · 5.3 Modeling domain behaviors around data · 5.3.1 Telling a story with data · 5.3.2 Represent runtime decisions as compile time algebraic data types · 5.4 Fleshing out the representation · 5.4.1 Creating wrapper types and being OK with comingled Identities · 5.4.2 Being OK with imperfect semantics · 5.4.3 Designing the algebra for Late Fees · 5.4.4 Modeling the decisions · 5.4.5 The high-level data model · 5.5 Interacting with legacy code · 5.5.1 Fitting into what’s already there · 5.5.2 Separate how you get the data from what you do with it · 5.6 Decoupling from the Tyranny of What's Already There · 5.7 The finished data model · 5.8 Wrapping up · 5.9 Summary

What you learn in chapter 5 →

Chapter 6: Implementing the Domain Model

The chapter introduction explains why implementing the invoicing domain model requires care with Java methods and decisions about code organization.

6.1 On the criteria by which we break down an implementation · 6.1.1 Functions, Purity, and Determinism · 6.1.2 How do we write pure functions in Java? · 6.1.3 The effect of deterministic functions on reasoning · 6.1.4 Functions let you work locally · 6.1.5 Functions are tables of immutable data in disguise · 6.1.6 Functions let us model relationships · 6.1.7 One last note on all this deterministic business · 6.2 Organizing code around determinism · 6.3 Implementing the deterministic core · 6.3.1 Implementing collectPastDue · 6.3.2 Implementing BuildDraft · 6.3.3 That really gross wrong feeling is a feature · 6.3.4 Implementing Assess Draft · 6.3.5 Dealing with optional · 6.3.6 It’s always OK to introduce more types! · 6.4 Implementing the non-deterministic shell · 6.4.1 Who owns the save logic? · 6.4.2 Treat legacy Entities as Data Transfer Objects · 6.5 Data is the ultimate interface · 6.6 Putting it all together · 6.7 Wrapping up · 6.8 Summary

What you learn in chapter 6 →

Chapter 7: Reasoning About Correctness

The introduction proposes algebraic reasoning about values and their relationships as a way to judge whether code is simpler.

7.1 We begin with an exercise · 7.2 Thinking Algebraically · 7.2.1 Standing on Shoulders, Not Toes · 7.3 Noticing algebraic operations in every day code · 7.4 The algebraic properties of binary operations · 7.5 Invariants, Properties, State, and an upside-down capital A · 7.5.1 Every possible state? Surely too inefficient to be practical! · 7.5.2 Expressing these ideas without code · 7.6 Associativity · 7.7 Noticing more properties · 7.7.1 Ordering as a property · 7.7.2 Monotonic Relationships between inputs and outputs · 7.7.3 The properties that define what it means to be correct · 7.8 Optional as a parallel world · 7.8.1 Dealing with the IDE telling us we're doing it wrong · 7.8.2 Lifting Binary Operator into the world of Optional · 7.8.3 Moving our algebra into the world of Optional · 7.9 The finished implementation · 7.10 A final note on representing algebraic ideas in code · 7.11 Wrapping up · 7.12 Summary

What you learn in chapter 7 →

Chapter 8: Business Rules as Data

The chapter introduces data as a starting point for modern Java design, contrasting it with Java’s reputation for inheritance-heavy abstractions.

8.1 Let’s start with an example · 8.1.1 What does it mean to be correct? · 8.2 Muscling through the rule implementation · 8.3 Capturing rules as plain data · 8.4 Building a simple Algebra · 8.4.1 Building better interfaces into the algebra · 8.5 Variation I: Deciding what data means · 8.6 Variation II: A more powerful interpreter for the same data · 8.7 Variation III: Adding Type Safety · 8.8 What did this cost us? · 8.9 But It doesn’t do everything! · 8.10 Data is flexible in a way that code isn’t · 8.11 Extending the algebra: · 8.12 Wrapping up · 8.13 Summary

What you learn in chapter 8 →

Chapter 9: Refactoring Legacy Code

The introduction frames data-oriented refactoring as a way to improve ordinary legacy code incrementally by bringing its hidden data to the surface.

9.1 A messy starting point · 9.2 Analyzing common problems in code · 9.2.1 Messy data modeling · 9.2.2 Uncontrolled mutation · 9.2.3 Sequential coupling · 9.2.4 Hidden knowledge, partial construction, and shotgun validation · 9.3 Fixing the problems · 9.3.1 Work backwards from invariants · 9.3.2 Draw boundaries with data · 9.3.3 Make validation about evidence rather than errors · 9.3.4 Write utilities that make data-oriented programs more expressive · 9.3.5 Keep mutation where useful, but use it to build data · 9.3.6 Now consider object boundaries · 9.4 Some encouragement on refactoring legacy code · 9.5 Wrapping up · 9.6 Summary

What you learn in chapter 9 →

Chapter 10: Data Oriented Architecture

The introduction frames data-oriented architecture as an approach in which objects serve as gatekeepers for exchanging data.

10.1 A small example · 10.1.1 Starting from scratch · 10.2 The Object Oriented Thought Process · 10.3 The Data Oriented Thought Process · 10.3.1 Resist the urge to abstract! · 10.4 A way of thinking about software architecture · 10.4.1 Start in the middle and work outward · 10.4.2 The role of objects in data-oriented programming · 10.4.3 Designing objects with functional core; imperative shell · 10.4.4 Keep resisting the urge to abstract! · 10.4.5 But what if it changes? · 10.4.6 Push your semantics into the external worlds · 10.4.7 Checks and balances · 10.4.8 Dealing with the outside world that uses our program · 10.4.9 Always watch your boundaries · 10.5 Good boundaries make change easy · 10.6 Wrapping up · 10.7 Summary

What you learn in chapter 10 →

Chapter 11: Data Oriented Testing

The chapter introduces data-oriented testing and emphasizes that how tests represent data affects their clarity.

11.1 A few definitions · 11.2 Data orientation makes tests better · 11.3 Writing data-oriented tests · 11.3.1 Use data to show what’s under test · 11.3.2 Data makes tests flexible · 11.3.3 Model side-effects with data · 11.3.4 Don’t be afraid to introduce new data types · 11.4 Avoiding common problems in test suites · 11.4.1 Randomize unused inputs to prevent coupling · 11.5 Using randomized data in tests · 11.5.1 Streams + randomization = infinite test data · 11.5.2 Exercise all the states in your program · 11.5.3 One test, multiple roles · 11.5.4 The most useful tests are often the simplest · 11.5.5 Verifying algebraic properties. · 11.5.6 Randomization is just another tool · 11.5.7 Favor using libraries when generating data · 11.6 A few closing thoughts on testing · 11.6.1 Data coverage is more important than test coverage · 11.6.2 Embrace the humble comment · 11.6.3 The best tests are the ones you don’t have to write · 11.7 Wrapping up · 11.8 Summary

What you learn in chapter 11 →

Chapter 12: Integration Testing

The introduction explains why integration tests matter for software that interacts with the world and why they are difficult to make reliable.

12.1 Writing Integration Tests · 12.2 Drive your integration tests with data · 12.3 Impose algebraic properties on your dependencies · 12.4 Embrace concurrency, beat up your software, and find bugs · 12.5 Regularly prune redundant tests! · 12.6 Building a reliable integration test suite · 12.7 Wrapping up · 12.8 Summary

What you learn in chapter 12 →

Concepts explained in this book

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.