Refactoring-Bad Smells in Code

Source: Internet
Author: User

/*

Author: Jiangong SUN

*/

 

 

 

1. Duplicated code

Extract method or Extract class

2. Long method

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

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. Modify the volume gun surgery volume bullet; opposite to the divergent change

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 attachment

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

Move method, Strategy, Visitor pattern

8. Data clumps Data dashboard

9. Basic Primitive obsession type paranoia

Replace data value with object, replace type code with class

10. Switch statements

Replace conditional with polymorphism

11. Parallel inheritance hierarchies Parallel inheritance System

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 redundancy 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 exaggerated the future

Remove parameter, collapse hierarchy, inline class

14. temporary field

Extract class, introduce nullable object

15. message chains over-coupled information chain

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 object, and so on.


Solution: hide delegate

16. middle man intermediary

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

 

 

 

 


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.