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. Binding的详细说明

    <DataGridTextColumn Width="*" Header=" 组合规则名称 " Binding="{Binding ComRul ...

  2. Html5 学习系列(四)文件操作API

    原文:Html5 学习系列(四)文件操作API 引言 在之前我们操作本地文件都是使用flash.silverlight或者第三方的activeX插件等技术,由于使用了这些技术后就很难进行跨平台.或者跨 ...

  3. 【C#】获取任意文件的缩略图

    原文:[C#]获取任意文件的缩略图 因为用shell取缩略图时,对于损坏的文件,读出来的图有黑边,所以就诞生了以下方法,不过这个效率要比用shell取的低3-4倍. 1.添加类WindowsThumb ...

  4. Sublime text追踪函数插件:ctags[转载]

    一.下载(择其一即可): 1)http://ctags.sourceforge.net/ 2)http://prdownloads.sourceforge.net/ctags/ 解压后单独取出ctag ...

  5. generate eml file

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD ...

  6. 微信小程序把玩(十五)checkbox组件

    原文:微信小程序把玩(十五)checkbox组件 不得不吐糟下checkbox默认样式真是有点略丑!!!checkbox组件为一个多选框被放到checkbox-group组中,并在checkbox-g ...

  7. Android多线程(三)

    上次讲了关于Android多线程中通信中Thread.Handler.Looper等的基础概念和基本用法,用现实世界两个人写信交流的过程来理解是再好不过了.但是不得不说这一套完整的细节的确很繁琐,好在 ...

  8. 简单图标转xaml代码

    工具 PhotoShopCC(2017) Blend 2017 原图 步骤 1,使用钢笔工具勾勒出大致路径 2,将工作路径转为形状路径 3,图层右键->复制SVG <svg xmlns=& ...

  9. Delphi 7学习开发控件(继承TGraphicControl只画一条线)

    我们知道使用Delphi快速开发,很大的一方面就是其强大的VCL控件,另外丰富的第三方控件也使得Delphi程序员更加快速的开发出所需要的程序.在此不特别介绍一些概念,只记录自己学习开发控件的步骤.假 ...

  10. T4随记

    关于T4模板的信息我就不赘述了,百度一大堆 MSDN的介绍 https://msdn.microsoft.com/zh-cn/library/bb126478.aspx 下面是简单的一个示例,从类中获 ...