What problem does it solve?
Domain Primitives & Always-Valid Domain Model remove dependence on raw primitive types by wrapping them in domain-specific, immutable types that enforce invariants at construction. This approach prevents invalid states, improves code readability, and enables stronger compiler-time guarantees. It provides a blueprint for modeling core domain concepts that are safe to compose and reason about.
Core Features & Use Cases
- Domain Primitives: wrap primitive values to enforce invariants at construction time.
- Always-Valid: ensure domain objects represent valid states and expose only safe operations.
- Smart Constructors & Validation: use factory methods to enforce invariants and prevent invalid instances.
- Range/NonEmpty & composite values: model bounded domains, sequences, and related value types like Money, Age, Email.
- Language-agnostic guidance: applies to Rust, TypeScript, Java, and other languages for broad applicability.
Quick Start
Define a domain primitive by wrapping a primitive value with a smart constructor that enforces invariants.