Code refactoring [iOS development]

Source: Internet
Author: User

Recently took over a year old project, get the code after a careful look, found there are more problems:

1. Not using SVN, or git, for management, all changes are in this project, where the problem is obvious, when the requirements are constantly added or modified, many will be silently cut off, there is no branch, version of the concept.

2. The use of many excellent Third-party library resources, but did not use cocoapods for management, there is a Third-party library resource upgrades, reconfiguration of the problem;

3. Mixed business and UI, the project in the initial design and development process, did not carry out a reasonable planning and co-ordination, each viewcontroller into its need to achieve the business, resulting in MVC in the C end of the extremely large, casual are thousands of lines of code, maintenance costs too high;

4. Casual use of notification, not to say that the notification mechanism is not good, with the appropriate, with less effort, but when I opened the main interface to see Viewdidload registered up to more than 20 notification, I really can not look directly, want to dozens;

5. But less packaging and modularity, as mentioned in the 3rd, the business follow the page, may be the same salesman, in different pages but many times, cumbersome, upgrade and change is also very troublesome.

6. Function naming is not clear, many business processing methods, using some such as nextxxx, Doxxx, finishxxx naming. Do not go deep inside the function to see the specific operation, it is difficult to understand what this step is to do.

7. But less documents and comments, due to the 6th reason, some pages, functions do not look inside, do not know what is used, there is no necessary notes and instructions.

Based on the problems identified above, it is important to realize the idea of the overall architecture and architecture in a project design and development phase. There is no good structure, just follow the demand, the east fill a piece, the West add a pen. When the project is more complex, the new requirements to add a lot of trouble, the old feature upgrade is more complex changes.

After taking over the project, I began to think about how to design the structure of a project, although I have seen some relevant knowledge, but also look at some excellent Third-party library file structure, but how to implement these excellent methods and ideas in their own project development is more important.

First, some basic ideas

1. Work divided into pieces of detail: No matter how complex the business process, to its as far as possible segmentation refinement, refinement of the process is also the business of each step of the understanding of a business process quantification, through the division of Business refinement, can also analyze a business workload is how big. specific to each function just do one thing, carry out the thought of doing one Thing only

The working mode of the pipeline is the core of the rise of modern industry, and this work mode is also the concrete and step-by-step of the basic work. At the same time, the refinement of the work can also correspond to the project WBS, management has become clear.

2. Small function attention package, large function attention to the modular: based on the work of a reasonable block and refinement, to the business of reasonable encapsulation and modularization, reduce the coupling between functional modules, can achieve a single business process, function point test. Implement the idea of high polymerization and low coupling.

The Assembly of the computer in the assembly line, with the modular motherboard, chassis, peripherals, assembly will become simple, can be a unit of testing and upgrades.

3. The structure of the project files should be clear: or the idea of the classification of modular, applied in the management of project documents, according to the project specific situation or according to the function, or according to the page of the hierarchical management, do not make a file become too large, implementation of large project small file ideas.

Remember before look at the UNIX design thought has mentioned big project small file This thought, the more huge project function, the more the document to be specific and sufficient refinement.

4. Name-readable: The best way to name a file or function is to "see the meaning of the name", rather than go into a file or function to see the processing logic. In addition to adding the necessary appropriate annotations. Ensure the use of modular functionality is smooth.

Ii. Practical Work

Based on the ideas that can be understood and used now, the project has been reconstructed for three weeks before and after the completion of the first phase of reconstruction.

1, combined with the project design documents to the original project to be split, the business process is independent of the business and the UI to separate abstraction.

2, the use of cocoapods, git management projects, record work content, but also record their own learning process.

3, the business function block refinement, modular business, the file is split, renamed, Improve code utilization.

4, abandoned a large number of use of notification logic, block, delegate and other modes, so that the project more clear, easy to upgrade later.

5, the establishment of the project file system, the modular business process to generate the corresponding logical documents.

Third, to the future work of the guiding significance

When a new project is launched in the future, it is necessary to design and use the name, structure, document management structure and document 4 system of the project reasonably.

In the process of project development, we should constantly stop to think about the work of the past, add a new function to think first, how to better access to the existing logic. In the spiral work progress, lets oneself to the project management thought and the method to be more mature.

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.