Can Your System Even Represent an Invalid State?¶
Type: Structure
Category: Domain
Audience: People who think enums solve everything
đ First Principle¶
If your system can represent something invalid,
someone will.
â ď¸ Common Leaks¶
User(status: Int)
with7
as a possible valueTask(state: String)
that can be"completed"
and"in-progress"
simultaneouslyNullable<Boolean>
â Why is your system unsure if something is true or false?
â Structural Fixes¶
- Use enums, sealed types, and tagged unions with intent
- Constructors should be unable to produce an invalid object
- Optional? Only when meaningful absence is part of the domain
- A domain model that âaccepts everythingâ is just a list of hazards
đ§ What This Question Is Really About¶
This isnât just âdo you have validation.â
Itâs: does your model forbid nonsenseâor just quietly permit it?
You donât need more tests.
You need fewer ways to go wrong.
â FAQ¶
-
Q: Isnât this over-design?
A: No. Itâs pre-accident design. -
Q: Canât I validate later?
A: Sureâafter someoneâs already been harmed.