oop-value-objects
Installation
SKILL.md
Value Objects
What it is
A Value Object encapsulates a value (or small group of related values) along with the behavior that belongs to it. Two instances are equal if their values are equal — identity doesn't matter. They are immutable: once created, they don't change.
Classic examples: Money, Email, PhoneNumber, Coordinate, DateRange, Color.
Would a fat model do?
Before extracting a value object, ask: is this value used in more than one model, or does it carry meaningful behavior beyond simple formatting? If it's just a string that lives in one model with one display helper, keep it in the model. Extract when:
- The same domain value (e.g. currency amounts) appears in multiple models with the same logic
- The value needs validation, formatting, arithmetic, or comparison that doesn't belong on the model itself
- You're writing the same
formatted_amount/amount_in_centshelper in three places