liveBook · Manning

Domain model

As explained in F# in Action: A Revised Edition of Get Programming with F#

A domain model is a software representation of the entities, relationships, rules, and behavior of a problem domain.

A domain model represents the entities, relationships, rules, and behavior of a real-world problem. F# makes modeling collaborative: developers and domain experts can explore ideas interactively with readable code and in-memory data, then move a working model into a console application or ASP.NET Core web API. section 1.5.1

Strong domain modeling makes business rules explicit in types. Specific types can encode invariants, improve readability, and prevent accidentally mixing values that happen to share a representation, such as separate City and Country wrapper types even when both contain strings. section 1.5.2

F# provides complementary tools for expressing a domain:

  • Use tuples and records to group related values and describe structured entities. section 9.4
  • Use discriminated unions to represent alternatives and mutually exclusive cases, such as passenger or buffet carriages. section 8.0 section 9.4
  • Use pattern matching and conditional logic to perform behavior over the modeled values. section 8.4 section 8.0

A train inventory domain

Model a train as carriages, an identification code, origin and destination stops, intermediate stops, and optional driver-change information. Represent carriage features such as quiet seating, Wi-Fi, and washrooms; distinguish first- and second-class passenger carriages; and allow buffet cars to serve hot food, cold food, or both. Then define operations for total seats, travel time between stops, and locating carriages with a requested feature. section 9.4

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Works through a train inventory model and its queries, while explicitly deferring time-zone handling.
Examples
Uses a train manifest with carriage types, route stops, features, class restrictions, food options, and inventory queries.
What it assumes
Builds from F# tuples, records, collections, and discriminated unions, with domain exploration beginning from customer requirements.
What you can do after
Build domain models in F# that encode business rules and support queries over structured data.
How it connects
Connects F# type systems, records, tuples, discriminated unions, pattern matching, and type-driven development.

Also explained in

Compare how 8 books explain domain model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.