The Don’t Repeat Yourself (DRY) principle states that duplication in logic should be eliminated via abstraction; duplication in process should be eliminated via automation.
Duplication is Waste
Adding additional, unnecessary code to a codebase increases the amount of work required to extend and maintain the software in the future.php
Duplicate code adds to technical debt. Whether the duplication stems from Copy Paste Programming or poor understanding of how to apply abstraction, it decreases the quality of the code. app
Duplication in process is also waste if it can be automated. Manual testing, manual build and integration processes, etc. should all be eliminated whenever possible through the use of automation.ide
Often, if-then and switch statements have a habit of being duplicated in multiple places within an application. ui
It’s common in secured applications to have different functionality available to users in certain roles, so the code may be littered with if-user-is-in-role checks. .net
Other applications may have been extended to deal with several similar but distinct kinds of data structures, with switch() statements at all levels of the workflow used to describe the differences in behavior each data structure should have. code
Wherever possible, refactor these conditionals using well-known design patterns to abstract the duplication into a single location within the codebase.ip
Once and Only Once can be considered a subset of the DRY principle.ci
The Open/Closed Principle only works when DRY is followed.get
The Single Responsibility Principle relies on DRY.workflow
SOLID and DRY Principles of Object Oriented Design on Pluralsight (includes 2 modules on DRY)
Don’t Repeat Yourself from 97 Things Every Programmer Should Know
Principles of Object Oriented Design course from Pluralsight