liveBook · Manning

Data model

As explained in The Art of Code

A data model is a representation of the information, structure, relationships, and constraints that a software system manipulates.

A data model makes a system’s information, relationships, units, and constraints visible in the structure of the code. Clear models put data first, allowing behavior to organize itself around meaningful concepts instead of hiding intent behind generic fields, methods, and boilerplate. section 4.0 section 4.4

Make ambiguous values carry their meaning

A constructor such as `new User("John", 180, 70)` leaves the numeric values and their units unclear. A model such as `PhysicalProfile("John", WeightInPounds(180), HeightInInches(70))` names the domain concepts, documents the units at the call site, and prevents arguments from being accidentally reversed. Extra types add protection when ambiguity or risk justifies their cost; they become harmful when they obscure a simple value. section 4.0

Shape a model around the data that actually drives behavior:

  • Name domain concepts explicitly rather than representing them with unexplained primitives. section 4.3
  • Keep units, categories, identity, state, ranges, and invariants close to the values they describe. section 4.3
  • Prefer small immutable data carriers when mutation is unnecessary, and flatten structures that hide meaning. section 4.4
  • Avoid over-modeling: introduce a type only when it adds clarity, protection, or a meaningful rule. section 4.0 section 4.3
Before making changes, identify the data the code is really manipulating.

Ask:

- What is the central data concept?
- Which values represent identity, state, unit, range, or category?
- Which values come from outside the system, and which are internal?
- Which values are temporary, derived, or persisted?
- Which values drive behavior?
- Which values naturally belong together?
- Which values are part of a public contract or generated model that cannot be changed directly?

Use the data-model inspection prompts to identify central concepts, value roles, boundaries, persistence, and behavior-driving data before refactoring. section 4.3

How The Art of Code covers it

How deep it goes
Develops practical modeling and refactoring principles, but stops short of prescribing a rigid universal method.
Examples
Uses ambiguous user attributes, typed height and weight values, immutable carriers, and refactoring inspection prompts.
What it assumes
Assumes existing behavior can be inspected, while teaching how to identify the data that behavior really manipulates.
What you can do after
Apply it by replacing ambiguous structures with precise, proportionate data types and simpler behavior.
How it connects
Connects domain modeling with immutability, encapsulation, invariants, pattern matching, and public API contracts.

Also explained in

Compare how 23 books explain data model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.