intermediate

DRY

Remove duplicated knowledge and business rules, but tolerate similar-looking code until the shared abstraction is stable and cheaper than repetition.

DRY (Don't Repeat Yourself) targets duplicated knowledge and business rules—not every similar-looking line of code. When two snippets evolve for different reasons, forcing abstraction creates coupling. Extract when the rule is truly shared and stable; tolerate duplication until the third similar case clarifies the abstraction.

DRY applies across layers: magic numbers, validation rules, and API error mapping should have one source of truth.

On interviews: show duplicated validation you would extract versus similar UI layout you would leave separate.

Common pitfalls: wrong abstraction from premature DRY, shared utils dumping ground, and copy-paste of business rules across services.

The trade-off is maintainability of shared truth versus flexibility of independent copies.

Checklist:

  • Distinguish duplicated knowledge from coincidence.
  • Extract stable business rules once.
  • Delete bad abstractions when needs diverge.