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.

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.

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.

Suspect Conditionals

Often, if-then and switch statements have a habit of being duplicated in multiple places within an application.

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.

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.

Wherever possible, refactor these conditionals using well-known design patterns to abstract the duplication into a single location within the codebase.

Related Principles

Once and Only Once can be considered a subset of the DRY principle.

The Open/Closed Principle only works when DRY is followed.

The Single Responsibility Principle relies on DRY.

Resources

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

2016 Software Craftsmanship Calendar

Don’t Repeat Yourself的更多相关文章

  1. mysql while,loop,repeat循环,符合条件跳出循环

    1.while循环 DELIMITER $$ DROP PROCEDURE IF EXISTS `sp_test_while`$$ CREATE PROCEDURE `sp_test_while`( ...

  2. MySQL中的while、repeat、loop循环

    循环一般在存储过程和存储函数中使用频繁,这里只给出最简单的示例 while delimiter $$ create procedure test_while() begin declare sum i ...

  3. MySQL-procedure(loop,repeat)

    在 MySQL-procedure(cursor,loop) 中将spam_keyword表中的文字全部分割到t表当中,且每一行的字都不重复,那t表可以用来当作一个小字典,只有1000来个字符,这次把 ...

  4. Shell 语法 if 、 case 、for 、 while、 until 、select 、repeat、子函数

    if语法 :   if [ expression ]    then   commandselif [ expression2 ]   then   commandselse   commandsfi ...

  5. unity mathf.repeat 截取操作

    截取操作,可用于浮点数. Mathf.Repeat(Time.realtimeSinceStartup, 3*blinkTime) > blinkTime;

  6. repeat语句

    一.repeat语句格式repeat语句用于"重复执行循环体,直到指定的条件为真时为止" repeat语句格式:repeat  语句1;  语句2;  --  语句n;until ...

  7. freeCodeCamp:Repeat a string repeat a string

    重复一个指定的字符串 num次,如果num是一个负数则返回一个空字符串. /*思路 fo循环将字符串重复num次并组成数组 将数组组成新的字符串并返回 */ function repeat(str, ...

  8. 从js的repeat方法谈js字符串与数组的扩展方法

    js将字符串重复N次的repeat方法的8个版本 /* *@desc: 将一个字符串重复自身N次 */ //版本1:利用空数组的join方法 function repeat(target, n) { ...

  9. HDU 4342History repeat itself 数学

    C - History repeat itself Time Limit:1000MS     Memory Limit:32768KB      Description Tom took the D ...

  10. [转]Using the Group Pane to Repeat Page Titles

    转自:http://www.wiseowl.co.uk/blog/s148/group-pane-advanced-mode.htm Repeating Page Headers in Reporti ...

随机推荐

  1. String 源码分析

    Java 源码阅读 - String String 类型看起来简单,实际上背后的复杂性基本可以涵盖了整个 Java 设计,涉及到设计模式(不可变对象).缓存(String Pool 的理念).JVM( ...

  2. centos搭建svn服务器并同步到web目录

    yum install subversion mkdir -v /root/svn cd /root/svn svnadmin create web cd web/conf/ vi passwd te ...

  3. Ionic3开发环境搭建-VS Code

    原文:Ionic3开发环境搭建-VS Code 一.Ionic3在VS Code中的开发环境搭建 1.全局安装Ionic包 npm install -g cordova ionic 使用 ionic ...

  4. Vue-cli入门(一)——项目搭建

    Vue-cli入门(一)——项目搭建 前言: Vue-cli是一款基于vue的项目脚手架工具,其集成了webpack环境和主要的依赖,对于我们的项目搭建.开发.打包.维护管理等都是非常的方便. 主要内 ...

  5. MASMPlus汇编之简单窗体

    .386 .model flat,stdcall option casemap:none ;include 定义 include   windows.inc include   gdi32.inc i ...

  6. 读unp并动手实践

    经过三个月的学习,我发现进度比较慢.照这个进度下去,平均一周花费5-6小时,还不知道读完全书需要多久. 现在做个计划,全书除开简介部分分为 基础 和 高级 套接字编程两部分,其中 基础可以分为 TCP ...

  7. SQL SERVER中UPDLOCK ,READPAST使用

    原文:SQL SERVER中UPDLOCK ,READPAST使用 SQL SERVER中中获取不重复数据: select top 1 * from orders with(UPDLOCK ,READ ...

  8. intellij开发安卓与genymotion配合

    原文:intellij开发安卓与genymotion配合 [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http: ...

  9. painter半透明的 底层窗口全透明背景

  10. Linux kernel version dirty

    在我们使用git来管理Linux Kernel的时候,在编译的时候会在你的kernel version加上git commit number 有时候还会出现dirty字样,字面意思是内核被污染的意思. ...