代码大全学习-27-重构(Refactoring)

重构是改善软件内在结构以提高可读性和易维护性。常见重构原因包括重复代码、过长函数、深嵌套循环等。本文列举了从数据、语句、函数、类到系统的重构方法,并强调了重构安全性的检查清单,以确保改进而非引入问题。
摘要由CSDN通过智能技术生成

重构是改变软件的内在结构从而让其更好理解更容易修改。在软件开发过程中随处可见它的身影。很多地方都可以用重构来改善,比如重复的代码,太长的函数,嵌套很深的循环等,下面是一个比较完整的list,需要重构的原因:

Checklist: Reasons to Refactor

  • Code is duplicated
  • A routine is too long
  • A loop is too long or too deeply nested
  • A class has poor cohesion
  • A class interface does not provide a consistent level of abstraction
  • A parameter list has too many parameters
  • Changes within a class tend to be compartmentalized
  • Changes require parallel modifications to multiple classes
  • Inheritance hierarchies have to be modified in parallel
  • Related data items that are used together are not organized into classes
  • A routine uses more features of another class than of its own class
  • A primitive data type is overloaded
  • A class doesn't do very much
  • A chain of routines passes tramp data
  • A middle man object isn't doing anything
  • One class is overly intimate with another
  • A routine has a poor name
  • Data members are public
  • A subclass uses only a small percentage of its parents' routines
  • Com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值