Agent skill
create-value-object
Create Value Object for domain modeling following DDD patterns. Use when you need to encapsulate primitive values with validation, business rules, and immutability. Creates reusable VOs like PriceField, EmailField, QuantityField with validation and domain logic.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/create-value-object
SKILL.md
Create Value Object
Generate immutable Value Object with validation and business rules.
When to Use
- Encapsulate primitive values (string, int, float)
- Add validation to domain values
- Avoid primitive obsession
- Create reusable domain concepts
Inputs/Outputs
| Input | Example | Output |
|---|---|---|
| name | PriceField | Shared/Entities/VO/ValueObjectName.php (if shared) |
| type | string, int | BC/Entities/VO/ValueObjectName.php (if BC-specific) |
| validation | ['min' => 0] | - |
| location | Shared, Admin | - |
Process
| Step | Action |
|---|---|
| Create | Use template: value-object.php.tpl |
| Validate | make cs-fixer && make stan |
Structure
Value Object (final readonly, private constructor, static factory):
final readonly class ValueObjectName {
private function __construct(private TypeHere $value) {}
public static function fromString(string $value): self {
if (empty($value)) {
throw InvalidValueObject::empty();
}
return new self($value);
}
public function toString(): string { return $this->value; }
public function equals(self $other): bool { return $this->value === $other->value; }
}
See: docs/GLOSSARY.md#value-object for detailed definition
Rules
Class Structure:
final readonlyclass, private constructor- Static factory:
fromString(),fromInt(),fromCents(), etc. - Immutable (no setters)
Validation:
- In factory method
- Throw domain exceptions (not generic)
- Clear error messages
Methods:
- Getter:
toString(),toInt(),toFloat() - Comparison:
equals(),isGreaterThan(), etc. - Business logic if needed (e.g.,
add(),multiply())
Location Decision:
Shared/Entities/VO/if used across multiple BCs (ResourceUuid, EmailField, NameField, PriceField)BC/Entities/VO/if BC-specific only (ArticleReference, SupplierCode, TaxRate)
Templates
value-object.php.tpl
Location: .claude/templates/
References
- Value Object definition:
docs/GLOSSARY.md#value-object - Value Object pattern:
docs/QUICK_REF.md#value-object-pattern - Architecture:
docs/architecture.md#value-objects - Shared VOs:
src/Shared/Entities/VO/
Related Skills
create-entity- Use VOs in entitiescreate-use-case- Pass VOs in requests
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?