Decide Abstraction Timing

When to abstract vs copy-paste. The rule of three.

attac-t Updated

File contents

Skill: Abstraction Timing

"Duplication is far cheaper than the wrong abstraction."

The Decision

Copy-Paste when:

  • First occurrence (always)
  • Second occurrence (usually)
  • Contexts differ slightly

Abstract when:

  • Third occurrence with same pattern
  • Change in one requires change in all
  • Test coverage becomes repetitive

The Heuristic

Ask: "If I change one, must I change all?"

The Quick Test

Ask Answer Use
First time seeing this pattern? Yes Copy-paste
Second time, same context? Yes Copy-paste (note it)
Third time, identical pattern? Yes Abstract
Slight variations each time? Yes Keep separate

Real-World Examples

See examples.md.

attac-t/the-foundry/tree/main/plugins/laravel-ddd/skills/decide-abstraction-timing commit be51ae245c

Frequently asked questions

npx skillmds@latest add attac-t/decide-abstraction-timing