Domain Modeling Table of Contents

Join the Launch List! 🚀

Enter your email address for updates as Domain Modeling, my new book, is written here on this site.

This is just a draft.

Introduction

How to use this book

I have designed this book to teach you valuable skills to build better software. This chapter will teach you how to use this book and your brain to improve your programming skills.

In this chapter, you will:

  • Decide if this book is right for you
  • Learn how to maximize your learning

Sections

  1. Who is this book for?
  2. The style of code in this book
  3. How to maximize learning

A map of the domain modeling journey

I have arranged the learnings and scenarios in this book to start with the most applicable and fundamental skills, gradually building to more profound skills. This chapter lays out three levels of modeling that map out your progress through the skills.

In this chapter, you will:

  • Understand what a domain model is and why they help you build better software.
  • See examples of models built at each of the three levels of domain modeling.

Sections

  1. What is a domain model?
  2. How domain modeling helps build better software
  3. An overview of the three levels of domain modeling
  4. Level 1: Data modeling example
  5. Level 2: Operation modeling example
  6. Level 3: Algebraic modeling example

Level 1: Data Modeling

Data modeling gives us the tools and skills to represent the possible states of a domain in data. At this level, we will learn to analyze a domain into a conceptual model, decide how to encode it as software, and evaluate a domain model for fit and convenience.

By the end of this level, you will be able to:

  • Encode a conceptual model in data
  • Analyze a domain for structure
  • Evaluate a domain model for quality
  • Explore different encodings for a conceptual model

Building a model of a well-analyzed domain

In this chapter, we build a data model of a domain with a pre-existing conceptual model. Working from a structured conceptual model will help us focus on choosing the correct encoding for our data.

In this chapter, you will:

  • Translate structural features of the conceptual model into code.
  • Experiment with different encodings for the same feature.

Sections

  1. Scenario: Fredo's Pizza
  2. Counting the states of a domain
  3. The many possibilities of encoding states
  4. Encoding structure: Alternatives for choices
  5. Encoding structure: Combinations for relationships
  6. Encoding structure: Mappings for conversions
  7. Encoding structure: Collections for one-to-many relationships
  8. Encoding structure: Collections for many-to-many relationships

Analyzing a new domain for structure

In the last chapter, we built a data model of a well-analyzed domain. Someone had already broken it down into a structured conceptual model. But how was that done? In this chapter, we will start from a new domain and use data modeling tools to analyze it.

In this chapter, you will:

  • Identify relevant concepts and relationships in a domain
  • Understand the value of building a data model to increase precision

Sections

  1. Scenario: A pizza delivery order
  2. Identifying important domain concepts and relationships
  3. Build directly in code to force precision
  4. Experiment with encodings to check for completeness
  5. Encoding structure: Names to refer to other things
  6. Encoding structure: Nesting for components

(below here needs more revision)

Evaluating a data model

Sections

  1. An analytical measure of model quality
  2. Precision and completeness measure the conceptual model
  3. Fit measures the domain model
  4. Scenario: Representing ingredients
  5. Stratified design to defer decisions

Level 2: Operation Modeling

At this level, we have considerable flexibility when representing and domain. That flexibility gives us too many decisions, each with unforeseeable consequences. Luckily, there is a lot of information in the operations we want to perform on the data. We start building the model with the operations, knowing we can always do data modeling later. By starting with the operations, we constrain the choices of data model to make the decision easier.

By the end of this level, you will be able to:

  • Build a domain model using function signatures
  • Evaluate functions in terms of their compliance with a signature
  • Model time explicitly
  • Model orthogonal domains to implement cross-cutting concerns

Build an interactive GUI

When building a GUI, it is essential to encode the operations a user of the GUI will perform. This chapter starts with the function signatures, which inform the eventual data operations.

In this chapter, you will:

  • Analyze a domain for operations
  • Learn the pattern for signatures of state-changing operations

Sections

  1. Scenario: Pizza editor
  2. A function's signature tells you everything a caller should need to know
  3. Mutations: functions that model a discrete change in state
  4. Equality is an important operation
  5. Optimize for time to fun

Removing corner cases from an operation

Sections

  1. Scenario: Removing an ingredient
  2. Total functions are well-defined over any combination of valid arguments
  3. How to make it total: Restrict arguments
  4. How to make it total: Augment return value
  5. How to make it total: Modify the meaning

Modeling state change over time

If your domain includes any notion of state change, you will need to model that state change at some point explicitly. This chapter deals with two ways of modeling state change over time, a history of states and a history of changes. We will use both to implement undo.

Sections

  1. Scenario: Undo in the editor
  2. State change: History of states
  3. State change: History of changes
  4. Convert operations into data using an interpreter

Modeling cross-cutting concerns

Sections

  1. Scenario: Asynchronous values
  2. Async model: Pessimistic updates
  3. Async model: Optimistic updates
  4. Identify cross-cutting concerns

Level 3: Algebraic Modeling

Building highly composable models

Sections

  1. Scenario: Vector graphics
  2. Begin by specifying compositions of operations
  3. Closure property: Nested expressions
  4. Associative property: Break solutio ns into subsolutions
  5. Implement concepts with functions to play faster
  6. Reify compositions into data using an interpreter

What an algebraic model is like to use

Sections

  1. Scenario: Pizza images
  2. Interpreting from one model to another
  3. Subsolution: Ingredients
  4. Subsolution: Dough, sauce, cheese

Another example of algebraic models

Sections

  1. Scenario: Ingredient arithmetic
  2. Commutative property: Apply operations in any order
  3. Identity value: Where to start
  4. Algebraic models flexibly solve problems at a high level