Data modeling designs representations around what domain information means, not merely around the objects that currently hold state. Start by naming the facts and constraints that must be true; then let those meanings shape types, attributes, and operations. A model is suspect when its types say something different from the data they represent, or when defensive checks repeatedly repair states the representation permits. section 3.6 section 3.0
Treat early code as a sketch, not a commitment. Move between prose definitions and small records, adding, removing, or separating attributes until each type conveys a coherent domain idea. This makes hidden assumptions visible and turns friction—nulls, flags, validation, or explanatory prose—into evidence that the model may be combining incompatible meanings. section 4.1.3 section 4.9
Separate a checklist template from a checklist run
A template is a named collection of steps; an instance is a particular run at a time. Putting isCompleted on Step makes a reusable template contain already-completed work. Remove that flag from Step, then represent completion as status associated with a particular instance and step. The model now distinguishes the definition of work from its execution. section 4.1.3
Use the shape of domain facts to choose a representation:
- Combine attributes with AND only when they all describe one coherent thing; a completed status can carry its instance, step, user, and completion time. section 4.2.1
- Split alternatives with OR when attributes apply to different states; separate types avoid null-filled records and impossible combinations. section 4.2.1 section 4.9
- Use records and sealed interfaces to make the permitted data shapes explicit, while recognizing that translating a model into Java still requires design judgment. section 4.2.1 section 4.8
- Model test scenarios as domain states rather than only as mock-driven paths, so each case states what is known about the system. section 11.3.4
Good models prevent work as well as organize code. When an invariant is captured in a type, impossible states cannot be constructed and do not need tests. Extra types are not, by themselves, a performance problem; measure actual JVM bottlenecks before weakening a useful representation. section 11.6.3 section 1.4
Listing 4.13 The finished data model
record Step(String name){}
record Template(String name, List<Step> steps){}
record Instance(
String name,
Instant date,
Template template
){}
record Status(
Instance instance, #A
Step step,
boolean isCompleted
){}Inspect the finished checklist model to see how reusable steps, templates, dated instances, and completion status become separate domain data. section 4.1.3
