# Craft Value Object

> Crafting Value Objects. Immutable, serialization-safe.

- Skill: `attac-t/craft-value-object` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add attac-t/craft-value-object`
- Raw SKILL.md: https://api.skillmd.com/api/skills/attac-t/craft-value-object/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: attac-t (https://skillmd.com/u/attac-t)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/attac-t/craft-value-object

---


# 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/](examples/).

