liveBook · Manning

Cartesian product

As explained in Data-Oriented Programming in Java

A Cartesian product is the set of all ordered tuples formed by choosing one element from each of several sets.

A Cartesian product forms a new set by combining one value from each component set. For a record, it describes every tuple of attribute values the type can represent. section 4.6.1

This is a practical design lens: adding attributes multiplies the number of representable states, including combinations that may be invalid in the domain. section 4.6.1

A beverage record

With Drinks = {Coffee, Tea} and Served = {Hot, Cold}, Beverage = Drinks × Served produces four states: Coffee/Hot, Tea/Hot, Coffee/Cold, and Tea/Cold.

The product perspective supports several kinds of reasoning:

  • Count a composite type by combining the values represented by each attribute; Optional attributes add an empty state. section 7.5

How Data-Oriented Programming in Java covers it

How deep it goes
Defines products, enumerates record states, and applies exhaustive assertions, stopping short of broader formal algebra.
Examples
Uses Beverage combinations and generated RawData states to illustrate enumeration and invariant checking.
What it assumes
Assumes familiarity with sets, Java records, attributes, and Optional values.
What you can do after
Evaluate/understand record state spaces, enumerate possible values, and test invariants across combinations.
How it connects
Connects product types and records with domain modeling, Optional values, invariants, and exhaustive testing.

Also explained in

Compare how 3 books explain Cartesian product →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming in Java. The section links point to the parts of the book it draws on.