Domain Modeling Made Functional – Scott Wlaschin

Discover how to create a robust domain model using functional programming principles and the type system, avoiding jargon and focusing on concepts and rules, to ensure correctness and maintainability.

Key takeaways
  • Domain modeling should be done with natural language and words used by experts in the domain.
  • Avoid using programmer jargon and focus on concepts and rules.
  • Use types to model constraints, such as email addresses and verified emails.
  • Represent options as a sum type or discriminated union.
  • Composition is key to building complex systems, and types are used to build bigger types from smaller ones.
  • Functional programming can be used to build domain models, and the type system can help catch errors at compile-time.
  • Modeling business rules as types can help ensure that errors are caught early and that the design is correct.
  • Domain modeling is about building a shared mental model, and using types and functions can help create a shared understanding.
  • Avoid null values and verbose code, and use immutable objects to ensure correctness.
  • Don’t mix up concepts, such as email addresses and phone numbers, and use different types to represent them.
  • Use control flow types to represent conditional logic.
  • Represent missing values as a choice type.
  • Use executable code to model the business logic, rather than using UML or other diagramming tools.
  • The type system can catch errors that wouldn’t be caught by a natural language description.
  • Domain modeling is a subjective process, and the goal is to create a model that is understandable and maintainable.