【转】简单设计四原则
来源:互联网 发布:网络产品结构培训班 编辑:程序博客网 时间:2024/05/16 17:05
- 代码可以工作;
- 沟通、表达业务逻辑;
- 没有重复代码;
- 没有额外代码
这四条简单设计原则是OO训练营和C训练营的灵魂,我们通过这个标准来衡量每个人的代码。
Four Principles of Simple Design
- It works
- At the most basic level the code must do what it is supposed to do. green bar – tests pass.
- It communicates
- You should be able to read the code directly. The code itself should express its intent. The best world is where the code reads like english. people have dozens of years of practice understanding english and the closer your code gets to english the easier will be to read. That is why we use full parameter names (‘probability’ instead of ‘p’) and we use method names that clearly express the intent of the method. If your code requires a lot comments then the code itself is not communicating. Seeing comments in your code likely points to an opportunity to improve the way the code communicates and then delete the comments.
- Short method names are prefered to long method names.
- Long method names often indicate the method is doing too much and could be broken into simpler methods. for example if your method name has an ‘and’ in it then it is probably doing too much
- Code should be easily understandable. if there are too many words it becomes harder to read and understand.
- No duplicate code
- Duplicate code creates barriers to maintanence and leads to the strong possibility of eventual contradiction. to work with duplicated code you have to know that it is duplicated and make modifications in all locations
- DRY (don’t repeat yourself)
- No extra code
- Cost of ongoing maintanence
- Having the extra code may inhibit good factoring of your code and hide valuable abstractions
- You can’t predict the future: your understanding of the system/design changes, requirements change, etc
- YAGNI (you ain’t gonna need it)
- 【转】简单设计四原则
- 设计模式四原则
- UI设计简单原则
- 设计原则利剑四--接口隔离原则
- 面向对象设计原则四
- 设计模式之四原则
- 四. PHP模式设计----设计原则
- 大话设计模式之四:1~5章(简单工厂模式 、策略模式、单一职责原则、开放封闭原则 、依赖倒转原则)
- 设计模式原则之四:迪米特法则
- 设计模式实践四-里氏替换原则
- 面向对象的设计原则四 - 里氏代换原则
- 设计模式六大原则(四)接口隔离原则
- 面向对象的设计原则四 - 里氏代换原则
- 设计原则(四)依赖倒置原则(DIP)
- 面向对象设计原则之四:依赖倒置原则
- 面向对象设计原则之四:依赖倒置原则
- 设计模式六大原则之四:接口隔离原则
- 面向对象设计原则之四--接口隔离原则
- poj2635
- 学习操作oracle.sql.Blob数据类型,向数据库插入Blob数据类型的数据
- UTF8编码表
- Python基础(2)-----类和对象
- POSIX多线程编程(一)
- 【转】简单设计四原则
- eclipse 启动tomcat 无法访问 详解
- 美副国务卿下周访华:将与中方磋商钓鱼岛问题-钓鱼岛-中日关系-美国副国务卿
- 【转】遗留系统重构案例
- (以实现)c++非递归层次二叉树
- 选择排序
- 浅谈三国时期功高震主者的成长历程和结局
- 我国今年约1.38万名穆斯林赴麦加朝觐-穆斯林-麦加-朝觐
- 3d游戏编程(转帖)