Skip to content
Back to skills

Create Value Object

ASecurity

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.

  • 666 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added February 8, 2026
businessphp

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill create-value-object --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Create Value Object?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Create Value Object
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-create-value-object/badge)](https://www.skillsdirectory.com/skills/majiayu000-create-value-object)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: create-value-object
description: 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.
---

# 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):
```php
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 readonly` class, 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 entities
- `create-use-case` - Pass VOs in requests

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.