SOLID & Design Patterns Interview Question #85
What is a rich domain model?
DDD Boundaries, Resilience, Caching & Practical ASP.NET Core Design Mid-Level Intermediate
Quick Interview Answer
A rich domain model combines state with business behavior and protects invariants through meaningful methods. Instead of exposing unrestricted setters, entities and value objects control valid state transitions.
Detailed Explanation
A rich domain model combines state with business behavior and protects invariants through meaningful methods. Instead of exposing unrestricted setters, entities and value objects control valid state transitions.
Rich models are valuable in complex domains, but they should not be forced into simple data-entry applications where the extra abstraction provides little benefit.
Code Example
public class Order
{
public OrderStatus Status { get; private set; }
public void Confirm()
{
if (Status != OrderStatus.Draft)
throw new DomainException("Order is not draft.");
Status = OrderStatus.Confirmed;
}
}