Introduce a Money value object
Refactor amount and currency primitives into a safe immutable value object.
Money is represented as number amount and string currency across refunds, credits, and invoices. Value Object: model a concept by its values, invariants, equality, and behavior rather than identity. The common trap is changing every API and database field at once, mixing a domain refactor with a migration. Define invariants Money stores integer minor units and uppercase ISO currency; constructor rejects unknown currency and non-integer minor units. A value object earns its keep by preventing bad combinations at creation. Add behavior Implement add, subtract, isZero, and format, with cross-currency operations rejected. Move repeated call-site rules into the concept itself. Refactor…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in