A domain model becomes muddy when one record carries fields whose meanings conflict, or when flags and nulls quietly encode mutually exclusive states. Algebraic data types make those choices explicit: combine facts that coexist with AND, and model alternatives that exclude one another with OR. In Java, records express the AND shape and sealed interfaces express the OR shape. section 4.1 section 4.9
A product type combines components with ×. A drink that is both a particular Drink and a Served state has the shape Drink × Served: every value contains both parts. A sum type combines alternatives with +. Coffee + Tea + Milk means a value is one of those choices. Sealing makes the boundary explicit: these options, and no others. The point is semantic precision, not replacing object-oriented design wholesale. section 4.6 section 4.9 section 4.7
Turn a runtime branch into domain data
Instead of making a decision disappear inside if/else code, return a sealed decision type such as BillableFee OR NotBillable OR NeedsApproval. Actions can then be deferred and interpreted separately: bill a billable fee, start approval, or preserve a rejected result. Making each branch a type exposes missing lifecycle states and lets the data model tell the process story before implementation details are fixed. section 5.3.2
The algebra also provides a compact sketching language. Use symbolic names such as A and B to reason about model shapes, then translate them into Java. Product and sum operations follow familiar algebraic laws, including commutation and distribution; optionality can be represented as a choice between a one-value empty case and a value of type A. These transformations can reveal duplicated structure before records and interfaces are refactored. section 4.6.3 section 4.6.4
Figure 4.19 Applying the distributive law over Sum and Product types to factor out duplication

Follow the distributive-law refactoring to see how algebraic notation identifies duplicated alternatives that can be factored into a clearer model. section 4.6.4





