2 Data, Identity, and Values

 

This chapter covers

  • Identity and change
  • Values and Value Objects
  • What “Data as Data” means
  • Modeling data with Records

In the first chapter, we started to look at the effect that representation has on our programs as a whole. Each choice we make ripples outward (either spreading good effects or ill depending on our modeling choices). By really focusing on what something in our domain is - what it represents -- we were able to use that understanding to radically simplify our code as a whole. There's another question we have to ask when we’re taking our first steps with data-oriented programming. It’s a bit more fundamental, but holds equal powers to reshape how and what we program with. It’s a little casual metaphysical question that goes like this: what does it mean to be something?

Programming with data as data forces us to tackle this question (at least superficially). One of the initial departures from the standard object-oriented toolkit is that when we’re programming with data, we don't have the familiar container of the object to give the things we're modeling their "it-ness." So, the question becomes: what is the canonical thing that flows through our program? What do we, the people writing the code, structure our code around?

2.1 Identity is about continuity over time

2.1.1 Object Identity

2.2 Values in the land of Identities

2.2.1 Building values out of values

2.2.2 Treating 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 is what we get when we give values meaning

2.3.1 What can data be?

2.4 Identity in the World of Data

2.4.1 Identity shapes how we program

2.5 Modeling Data and Values with Records

2.5.1 Compact Constructors

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

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

2.5.4 Some other niceties that come with records

2.6 What to do if you’re on a JDK older than 17

2.7 Wrapping up

2.8 Summary