- Transaction script pattern
- Active record pattern
- Domain model pattern
- Event-sourced Domain Model Pattern
What to choose?
An effective heuristic to choose which pattern to use for the given subdomain:
- Track money or monetary transactions? Provide audit log or deep analysis required?Event-sourced domain model. Otherwiseβ¦
- Complex business logic? Domain model. Otherwiseβ¦
- Complex data structures? Active record. Otherwiseβ¦
- Transaction script.
Evaluate business logic complexity
Two heuristics can be used:
- Complex business logic includes:
- business rules,
- invariants,
- algorithms. Simple business logic mostly validates the inputs.
- If ubiquitous language of the domain mainly describes CRUD operations, then itβs simple. If not describes complicated business processes and rules, then the business logic is complex.