11/10/2026
Passing raw integers, floats, and strings across your domain services isn't lightweight programming. It is Primitive Obsession masking business risks.
A foundational design pattern detailed in Chapters 4 & 5 of is replacing primitive language types (`float`, `string`, `array`) with domain-driven Value Objects.
When financial calculations, email addresses, or geographic coordinates are passed around as raw primitives, the responsibility of validating invariants is scattered across dozens of controllers and services.
The 3 Core Vulnerabilities of Primitive Obsession :
1. Implicit Invariant Violations: A `float $price` accepts negative values, zero allocations, or precision rounding errors (`0.1 + 0.2 = 0.30000000000000004`). Primitive types lack domain boundaries.
2. Context Loss (The Currency Mismatch Trap): Passing `$amount = 500` loses unit context. Without an explicit encapsulated currency, operations like `$total += $discount` can silently add USD to EUR without throwing runtime exceptions.
3. Duplicated Defensive Validation: Every method accepting a raw string must re-validate formatting (e.g. `preg_match` for emails or phone numbers), resulting in repeated, noisy validation logic across your codebase.
Architectural Blueprint: Value Objects
```
┌─────────────────────────────────────────────────────────────┐
│ PRIMITIVE OBSESSION (Anti-Pattern) │
│ float $amount = -500.00; string $currency = "USD"; │
│ (No Invariants, Rounding Errors, Silent Currency Leaks) │
├─────────────────────────────────────────────────────────────┤
│ IMMUTABLE VALUE OBJECT (DDD) │
│ Money { amountInCents: 50000, currency: USD } │
│ (Self-Validating, Immutable Operations, Value Equality) │
└─────────────────────────────────────────────────────────────┘
```
The 3 Pillars of a Value Object:
Self-Encapsulated Validation: The object constructor validates all domain rules upon instantiation. An invalid Value Object can never exist in memory.
Immutability: Value Objects do not expose setters. Any state transformation returns a new instance (`$money-add($otherMoney)`), eliminating unexpected side-effects across ex*****on threads.
Structural Value Equality: Equality is determined by property attributes rather than memory identity pointers (`$usd100->equals($usd100_copy) === true`).
Measured System Transformations:
Engineering Impact: Replacing raw primitive floats with strict `Money` and `Currency` Value Objects across checkout gateways eliminated floating-point precision defects and currency mismatch errors 100%.
Operational Result: Reduced regression testing overhead and bug-fix cycles on billing pipelines , drastically speeding up feature delivery times.
The Architectural Takeaway: Stop letting raw language primitives represent complex domain concepts. Encapsulate business invariants directly inside self-validating, immutable Value Objects.
👉 Is your SaaS billing engine or financial ledger suffering from floating-point rounding errors or weak domain validation?
Qualify your system constraints in under 3 minutes, and receive Supto's initial technical hypothesis within 72 hours: https://nexidant.com/profile