Don’t Repeat Yourself
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的更多相关文章
- mysql while,loop,repeat循环,符合条件跳出循环
1.while循环 DELIMITER $$ DROP PROCEDURE IF EXISTS `sp_test_while`$$ CREATE PROCEDURE `sp_test_while`( ...
- MySQL中的while、repeat、loop循环
循环一般在存储过程和存储函数中使用频繁,这里只给出最简单的示例 while delimiter $$ create procedure test_while() begin declare sum i ...
- MySQL-procedure(loop,repeat)
在 MySQL-procedure(cursor,loop) 中将spam_keyword表中的文字全部分割到t表当中,且每一行的字都不重复,那t表可以用来当作一个小字典,只有1000来个字符,这次把 ...
- Shell 语法 if 、 case 、for 、 while、 until 、select 、repeat、子函数
if语法 : if [ expression ] then commandselif [ expression2 ] then commandselse commandsfi ...
- unity mathf.repeat 截取操作
截取操作,可用于浮点数. Mathf.Repeat(Time.realtimeSinceStartup, 3*blinkTime) > blinkTime;
- repeat语句
一.repeat语句格式repeat语句用于"重复执行循环体,直到指定的条件为真时为止" repeat语句格式:repeat 语句1; 语句2; -- 语句n;until ...
- freeCodeCamp:Repeat a string repeat a string
重复一个指定的字符串 num次,如果num是一个负数则返回一个空字符串. /*思路 fo循环将字符串重复num次并组成数组 将数组组成新的字符串并返回 */ function repeat(str, ...
- 从js的repeat方法谈js字符串与数组的扩展方法
js将字符串重复N次的repeat方法的8个版本 /* *@desc: 将一个字符串重复自身N次 */ //版本1:利用空数组的join方法 function repeat(target, n) { ...
- HDU 4342History repeat itself 数学
C - History repeat itself Time Limit:1000MS Memory Limit:32768KB Description Tom took the D ...
- [转]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 ...
随机推荐
- WPF特效-粒子动画
原文:WPF特效-粒子动画 WPF实现泡泡龙小游戏效果. /// -Ball to Ball Collision - Detection and Handling /// http:// ...
- c# 自定义公共类CallFunction-调用函数信息帮助类
/// <summary> /// 调用函数信息 /// </summary> public class CallFunction { /// <summary> ...
- Windows Phone 8.1之应用设置存储的简单应用
应用设置存储主要分为本地存储和漫游存储两种方式.本地存储的指将应用的设置信息存储在本地存储空间中,而漫游存储则是指将应用的设置信息存储在网络服务器中.相对于本地存储而言,漫游存储支持多台设备之间的应用 ...
- android 录屏
录屏,google了一下,记录下来,以免FQ android 4.4 录屏可通过adb:adb shell screenrecord /sdcard/video.mp4 (未测试) android 5 ...
- 中国自主X86处理器工艺跃进:国产28nm升级16nm(上海兆芯)
提到X86处理器,世人皆知Intel.AMD,殊不知还有个VIA(威盛),在Intel反垄断世纪大战中VIA公司作为Intel霸权的受害者也最终确认了X86授权,不过VIA与前面两家的实力相差太远,X ...
- 分享基于.NET动态编译&Newtonsoft.Json封装实现JSON转换器(JsonConverter)原理及JSON操作技巧
看文章标题就知道,本文的主题就是关于JSON,JSON转换器(JsonConverter)具有将C#定义的类源代码直接转换成对应的JSON字符串,以及将JSON字符串转换成对应的C#定义的类源代码,而 ...
- QTableWidget和 QTableView翻页效果(准确计算Scroll,然后使用setSliderPosition函数)
以QTableView举例,QTableWidget使用相同 int CQTTableViewPageSwitch::pageCount(QTableView *p)//QTableView 总页 ...
- 关于Eurekalog解决不能发邮件的问题
最近无意中发现在盒子论坛中有人回答了本文的问题,最后在Eurekalog的安装目录中的ExceptionLog.pas找到了多发送的Rest命令的地方,现传上来,有需要的朋友下载下面的文件. 因为16 ...
- QT运行cmd指令(两种办法:QProcess.start然后waitForFinished,运行cmd /c命令)
QProcess p(); p.start("route");//写入要运行的指令即可 p.waitForStarted(); p.waitForFinished(); qDebu ...
- JS数据结构第三篇---双向链表和循环链表之约瑟夫问题
一.双向链表 在上文<JS数据结构第二篇---链表>中描述的是单向链表.单向链表是指每个节点都存有指向下一个节点的地址,双向链表则是在单向链表的基础上,给每个节点增加一个指向上一个节点的地 ...