Course contentsShow
← Software Engineering
Lesson 168 of 1,9335. Software Design PrinciplesFree lesson

Don't Repeat Yourself (DRY)

Discover why every piece of knowledge should have a single, authoritative representation in a system to prevent inconsistency.

Don't Repeat Yourself (DRY)

What you'll learn: You'll understand why duplicating knowledge in your system leads to maintenance nightmares and how to prevent it.

The Core Idea

Don't Repeat Yourself (DRY) means that every piece of knowledge—every rule, calculation, or definition—should exist in exactly one place in your system. When you duplicate logic, data formats, or business rules across multiple locations, you create a maintenance burden: if something changes, you must remember to update it everywhere. Miss one spot, and your system becomes inconsistent.

Why This Matters

Think of a recipe book where the instruction "preheat oven to 350°F" appears in 20 different recipes. If you discover the oven temperature should actually be 375°F for those dishes, you'd need to update all 20 pages. Miss even one, and someone following that recipe gets the wrong result.

The same happens in software. Imagine validation logic for an email address duplicated across three different files. When requirements change (maybe you now accept plus signs in addresses), you must update all three locations. Forget one, and some parts of your system accept valid emails while others reject them.

How DRY Connects to Earlier Principles

This builds directly on Abstraction and Information Hiding: when you hide implementation details behind a single interface, you naturally avoid duplication. It also supports Separation of Concerns: each concern gets its own authoritative home.

The Single Source of Truth

DRY creates what's called a "single source of truth"—one authoritative place where each piece of knowledge lives. Changes happen once, and the entire system stays consistent.

Key Takeaway: Every piece of knowledge should have a single, authoritative representation in your system; duplication creates maintenance burden and invites inconsistency.