Refactoring - Bad Smells in Code

/*

Author: Jiangong SUN

*/


There is a list of refactoring techniques with examples.

http://www.refactoring.com/catalog/


1. Duplicated code

Extract method or Extract class

2. Long method

Extract method, Inline method, replace temp variable by query, Parameter object(DTO), Replace method by method object

http://www.refactoring.com/catalog/splitTemporaryVariable.html

3. Large class

Extract class, extract subclass, 

4. Long parameter list

Preserve whole object, Introduce parameter object

5. Divergent change发散式变化

Extract class: divide class into different sub classes, in this way, several changes in a class can be made into several sub classes.

6. Shortgun surgery 霰弹修改; 和发散式变化正相反

Move method, move field: put all codes need to be modified into a class for preventing from forgetness in a lot of differenct classes. 

7. Feature Envy 依恋情结

symptom: a method use a lot of method in another class.

Move method, Strategy, Visitor pattern

8. Data clumps 数据泥团

9. Primitive obsession 基本类型偏执

Replace data value with object, replace type code with class

10. Switch statements : switch 惊悚现身

Replace conditional with polymorphism

11. Parallel inheritance hierarchies 平行继承体系

symptom: when you create a subclass for a class, you have to create a subclass for another class.

solution: make sure that instances of one hierarchy refer to instances of the other

12. Lazy class冗赘类

symptom: a class is not doing a lot of work

solution: inline class, means moving all it's features into another class.

13. speculative generality 夸夸其谈未来性

remove parameter, collapse hierarchy, inline class

14. temporary field 暂时字段

extract class, introduce nullable object

15. message chains过度耦合的信息链

symptom: You see message chains when a client asks one object for another object, which the client then asks for yet another object, which the client then asks for yet another another object, and so on.

solution: hide delegate

16. middle man 中间人

delegate

17. inappropriate intimacy 不合适的亲昵行为

extract method, extract class

18. alternative classes with different interfaces 

19. incomplete library class

20. data class

21. refused requests

22. comments

Extract method, Rename method




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值