Craft Value Object

Crafting Value Objects. Immutable, serialization-safe.

attac-t Updated 1 repo stars

File contents

Skill: Craft Value Object

"Invalid objects should be impossible to create."

The Standard

  1. Self-Validating: Validate in constructor. Invalid state throws immediately.
  2. Immutable: readonly class. No setters. Clone to modify.
  3. Defensive Construction: Private constructor + named factories for controlled creation.
  4. Serializable: Must survive queue serialization. No closures, no resources.

The Anti-Patterns

❌ Don't ✅ Do Why
Mutable properties readonly class VOs don't change
Skip validation Validate in constructor Invalid VOs shouldn't exist
Complex dependencies Primitives + other VOs Must serialize cleanly
Entity with no ID Use VO intentionally Different concepts

Real-World Examples

See examples/.

attac-t/the-foundry commit 4fa8762989

Frequently asked questions

npx get-skill add attac-t/craft-value-object