liveBook · Manning

Data carrier

As explained in The Art of Code

A data carrier is a small structure whose purpose is to hold and communicate a defined set of values.

A data carrier is a small, explicit structure for holding and communicating a defined set of values. Model the data before writing behavior, name its meaning, keep its invariants nearby, and prefer immutability when mutation is unnecessary. section 4.3

Make intent visible

Replace a generic User or a bare numeric value with a meaningful structure such as PhysicalProfile or WeightInPounds. Likewise, represent a composite key, range, unit, or short-lived method result explicitly when the structure improves understanding without creating needless complexity. section 4.3

Use a data carrier when it earns its place by reducing ambiguity or protecting meaning:

  • Keep validation rules near the data they protect and reject invalid states early. section 4.3
  • Use clearer types when several same-typed arguments can be swapped, and use enums for fixed categories. section 4.3
  • Flatten deeply nested structures where a simpler model, such as a composite key, communicates more clearly. section 4.3

How The Art of Code covers it

How deep it goes
Explains naming, invariants, immutability, construction, categories, and flattening, while stopping short of language-specific implementation.
Examples
Uses PhysicalProfile, WeightInPounds, composite keys, ranges, units, and short-lived method results as concrete carrier examples.
What you can do after
Evaluate data models for ambiguity, misplaced validation, unnecessary mutability, and structure that adds complexity without understanding.
How it connects
Connects data carriers with data modeling, invariants, immutability, enums, composite keys, and pattern matching.

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.