[Reconstruction learning] 02 where is reconstruction ?, Reconstruction learning 02

Source: Internet
Author: User

[Reconstruction learning] 02 where is reconstruction ?, Reconstruction learning 02

1. duplicate code

Solution:

  • Duplicate code is located in the same class: extract new functions for calling
  • Duplicate codes are located in different subclasses: extract them into functions and put them into the parent class.
  • Duplicate code is in a completely unrelated class: extract a new class and put the repeated code into the new class.
  • Duplicate code is not exactly the same, and there are some slight differences: the template method is used to solve the problem.

2. Function length and parameter column length are too long

Modification point:

  • There may be a change point in the place where there are comments, because since a place is worth writing comments, there is a possibility to extract it, even if it only has one line of code
  • Conditional expressions and loops: separates the branch logic from the Implementation Details and functions them. The loop can be placed in a separate function.

Solution:

  • There are not too many parameters and temporary variables: extract them into new functions for calling (there are too many temporary variables and parameters, which may lead to improved readability of the extracted functions)
  • Many temporary variables: replace the temporary variables with the query method, and then extract them.
  • Too many parameters: the reference parameter column is too long.
  • There are still a lot of temporary variables and parameters: Replace the method with the method object, simply put, create a class, use the temporary variable as the field, and then extract the code into the Method

3. Too large class

Solution: extract new independent classes or subclasses

4. The parameter column is too long.

  Solution:

  • Object substitution method: put multiple parameters into a single parameter object before passing (not only improves readability, but also reduces stack space and improves performance because only references are passed)
  • Function substitution method: Check whether these parameters can be replaced by functions. Simply put, the calculation part of these parameters is put into a function, and the returned results are uploaded.

5. Divergent changes (a class is subject to multiple changes and seems to be a single responsibility principle) goals: external changes correspond to the classes to be modified one by one

 Change Point: Once the software changes, but all changes to the same class, it indicates that such responsibilities are repeated.

Solution: Find all the changes caused by a special reason and extract them to another class.

6. Modify multiple classes with one change)Objective: The External changes correspond to the classes to be modified one by one.

  Modification point: Once the software changes, many classes need to be modified.

Solution: Find the many changes in different classes caused by a change, and put the changes in each class into a class.

7. Attachment plot

Modification point:

When a function of a class calls a large number of functions of another class for computation, the attachment plot appears.

In the world of 1 and 0, there is such a word with artistic temperament, so we can understand it with the means of Literature and Art: when your girlfriend often goes to someone else's house, you need to know more or less.

Solution:

If this code is completely attached to another class, then extract this part of the code with attachment plot into a function and put it into another class (this tells us to learn to let go when a woman does not love you at all ?)

However, it is not that simple in many cases. Do both classes have attachment? (But most of the time it's not that simple. What do she love ?)

Then we can determine which class has the data most used by this function, and then put this function together with those data. (Let her find someone if she has more advantages than her ?)

No wonder everyone said that programmers are good men @_@

However, Martin said:

The preceding steps are much simpler if you extract the code into several smaller independent functions. (Forgive me for saying that I have left leg and left hand. I have handed you the knife. Are you free ?)

-- It's terrible. Let me calm down and continue tomorrow.

8. data dashboard

9. Basic Type paranoia

10. Thrilling appearance of Switch

11. Parallel Inheritance System

12. Redundancy

13. Talk about the future

14. Confusing temporary Fields

15. Over-coupled message chains

16. Intermediary

17. Relationship between friends

18. Similar classes

19. Imperfect Database

20. Pure data

21. Rejected gifts

22. Too many comments

 

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.