[Reconstruction learning] 11. Large reconstruction and reconstruction 11

Source: Internet
Author: User

[Reconstruction learning] 11. Large reconstruction and reconstruction 11

Well, all of the above are simple examples. Now we start with large refactoring.

For large refactoring, the situation is complex and variable, and it takes a long time. Most of the previous simple Refactoring can be completed within one hour, but it may take several months or even several years for large refactoring. If it is a running system, it can only be reconstructed a little bit every day.

(I'm afraid there are few such companies in China. Therefore, we need to develop the habit of restructuring at any time, and do not dig holes to bury the best for ourselves. No one can rebuild for such a long time, especially when you are a low-end programmer. You have to believe that all your lazy actions will cause trouble for your future work. Unless you leave tomorrow, your pot may be carried back to me. When you arrive at a new company, you will find that you have become a back pot .)

1. sort out and break down the inheritance system

Modification point: an inheritance system has two responsibilities at the same time. If the subclass names of all classes at a specific level in the inheritance system start with the same adjectives, then the system may assume two different responsibilities.

Practice: establish two inheritance systems and enable one of them to call the other through the delegation relationship.

Motivation: chaotic inheritance systems can lead to repeated code.

Well, in short, you can understand it as the bridge mode.

2. Convert process design into Object Design

Modification point: the C-language code is displayed.

Practice: convert a data record into an object, divide the behavior of a large part into small parts, and move the behavior to the relevant object.

3. separate fields from expressions/displays

Modification point: some GUI classes contain business logic

Practice: Separate domain logic and establish independent domain classes for them

4. Extract the inheritance system

Modify point: you have done too much work for a class, some of which are completed with a large number of conditional expressions

Practice: Establish an inheritance system and use a subclass to represent a special situation

 

Summary:

Well, the above four points are very general, but they actually include a lot of things.

The more complicated the things, the easier it is to talk about.

Just like I said, it's easy to write a registration system, but it's not easy to implement.

Most of the time, we don't want to modify other people's code, because the business may be complicated, and he may also write poorly.

The only thing you must do is at least make sure that your code is easily maintained by others!

 

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.