Some thoughts on code refactoring

Recently, the company engaged in zhongtaihua again. I was lucky to participate in the reconstruction of one of the projects. I learned a lot from it and felt a lot.

1. Preparatory work

As a program ape, refactoring code is a common thing. The purpose of refactoring code is to make the code better adapt to the subsequent development and changes.

When you're going to refactor your code, think first. Why do you refactor? It is necessary to invest a certain amount of time and manpower in reconfiguration. On the basis of existing needs, we need to consider whether we can stably take time out for reconfiguration? When human time is available, when you plan to refactor some part of the code logic, you still have to ask yourself a few questions to help you better clarify your refactoring ideas:

If these problems are not big problems for you, you have basically thought about this part of code refactoring clearly.

2. Reconfiguration Design

1. Refactoring framework

For framework refactoring, you have to figure out what problems the old framework has. Does the new framework completely solve these problems or reduce the possibility of these problems.

For this part of the business I am responsible for, the existing framework business logic has been confused. Two different business scenarios mix a set of code logic, and the business logic is mixed with each other. When you modify a business function, it will easily affect another module. QA also needs to return to another business scenario, resulting in a waste of manpower and time.

Just taking advantage of the opportunity of Zhongtai output, I'm ready to reconstruct it.

The project I participated in is relatively simple. MVP is adopted as a whole, which is divided into three layers: interface layer, foundation layer and business layer.

In fact, MVP mode was also adopted in the past, but there was no layering before. With the continuous growth of business, there are more and more business logic, resulting in more confusion of the whole code business logic.

3. Some experience of code refactoring

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>