Duplication & Abstraction
Recognize hidden duplication and choose the right abstraction to eliminate it.
Duplication Is Always a Design Flaw
Every piece of duplication is a missed abstraction. The question is not "should I remove this duplicate?" — the answer is always yes. The question is "what is the right abstraction?"
Types of Duplication
Obvious: identical code blocks. Subtle: same algorithm in different forms. Structural: same data shape defined multiple times. Switch/if-else: the same condition scattered across the codebase.
Code Challenge
Find the duplication type, then choose the right abstraction.
💡Key takeaway
Name the thing you're duplicating. The right abstraction reveals itself once you can articulate the concept.
🔧 Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it — it helps us fix it fast.
Hint: G5 — Duplication. Every time you copy code, ask: what concept am I duplicating? Name it, extract it.
✗ Your version