Decide Dto Vs Array

When to use DTO vs array. Type safety threshold.

attac-t 0c1fb66 2 files · 3.3 KB Updated

File contents

Skill: DTO vs Array

"Arrays are bags of anything. DTOs are contracts."

The Decision

Use Array when:

  • Quick prototyping / exploration
  • Single-use, local scope
  • Framework requires it (config, etc.)

Use DTO when:

  • Data crosses boundaries (controller → action)
  • Same structure appears 2+ times
  • Validation needed
  • IDE autocomplete matters

The Heuristic

Ask: "Will another developer need to know what's in this?"

The Quick Test

Ask Answer Use
Does it cross a class boundary? Yes DTO
Is it reused elsewhere? Yes DTO
Does it need validation? Yes DTO
Is it a quick local variable? Yes Array

Real-World Examples

See examples.md.

attac-t/the-foundry/tree/main/plugins/laravel-ddd/skills/decide-dto-vs-array commit 0c1fb66642

Frequently asked questions

npx skillmds@latest add attac-t/decide-dto-vs-array