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.The content you see here is just a draft and is subject to change.
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
- Who is this book for?
- The style of code in this book
- 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
- What is a domain model?
- How domain modeling helps build better software
- An overview of the three levels of domain modeling
- Level 1: Data modeling example
- Level 2: Operation modeling example
- 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
- Scenario: Fredo's Pizza
- Counting the states of a domain
- The many possibilities of encoding states
- Encoding structure: Alternatives for choices
- Encoding structure: Combinations for relationships
- Encoding structure: Mappings for conversions
- Encoding structure: Collections for one-to-many relationships
- 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
- Scenario: A pizza delivery order
- Identifying important domain concepts and relationships
- Build directly in code to force precision
- Experiment with encodings to check for completeness
- Encoding structure: Names to refer to other things
- Encoding structure: Nesting for components
(below here needs more revision)
Evaluating a data model
Sections
- An analytical measure of model quality
- Precision and completeness measure the conceptual model
- Fit measures the domain model
- Scenario: Representing ingredients
- 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
- Scenario: Pizza editor
- A function's signature tells you everything a caller should need to know
- Mutations: functions that model a discrete change in state
- Equality is an important operation
- Optimize for time to fun
Removing corner cases from an operation
Sections
- Scenario: Removing an ingredient
- Total functions are well-defined over any combination of valid arguments
- How to make it total: Restrict arguments
- How to make it total: Augment return value
- 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
- Scenario: Undo in the editor
- State change: History of states
- State change: History of changes
- Convert operations into data using an interpreter
Modeling cross-cutting concerns
Sections
- Scenario: Asynchronous values
- Async model: Pessimistic updates
- Async model: Optimistic updates
- Identify cross-cutting concerns
Level 3: Algebraic Modeling
Building highly composable models
Sections
- Scenario: Vector graphics
- Begin by specifying compositions of operations
- Closure property: Nested expressions
- Associative property: Break solutio ns into subsolutions
- Implement concepts with functions to play faster
- Reify compositions into data using an interpreter
What an algebraic model is like to use
Sections
- Scenario: Pizza images
- Interpreting from one model to another
- Subsolution: Ingredients
- Subsolution: Dough, sauce, cheese
Another example of algebraic models
Sections
- Scenario: Ingredient arithmetic
- Commutative property: Apply operations in any order
- Identity value: Where to start
- Algebraic models flexibly solve problems at a high level