Android project code reconstruction ideas summary, android Reconstruction

Source: Internet
Author: User

Android project code reconstruction ideas summary, android Reconstruction

The fundamental idea of code refactoring is modularization, flexibility, high cohesion, and low coupling.


Android project code reconstruction:

Extract public basic resources and tool classes unrelated to the business logic to a lib project. The main program only contains the code and tool classes related to the business logic:

1. Extract public resources, including:

String. xml

Color. xml

Styel. xml

Drable custom shap, selector, and anim

These resources are basically irrelevant to the business logic of the program. placing them in the main project will only increase the amount of code that affects the understanding of the business logic of the program.

The unique resources of a project can inherit the resources of the lib library project and overwrite the special resources, for example, the basic button shapes defined in the lib project style include the default size, Default background, and text size, when a special style is defined in the main project, it is inherited from the style in the lib project and then covers the elements such as the text color and background color as needed. After the definition, the project will reference the base style directly or further refine the customization.

During the extraction process, if it is found to be useful, you can extract public items to the next layer as much as possible, as long as it is irrelevant to the project, as far as possible to be extracted to the lib project, the development process may consume more energy in the early stage, however, when a project comes down, in addition to gaining project-related experience, you also have a powerful basic resource library unrelated to the project for new project development, you can develop based on a basic resource library that has been constantly optimized. Many low-level codes and jobs do not require repetitive work.

Ps: my personal opinions on uidesign:

Try not to use a cut chart if you can implement your own xml. For example, buttons, gradient backgrounds, and solid background can all be painted by yourself.

The use of the cut graph is heavily dependent on the artist's personal quality and cut graph quality and will increase the size of the application. You need to replace the cut graph adjustment when changing the program style color later, if the above resources use the custom background xml resources, you only need to change the color field to adjust the color and style of the application.

If I want to make an application by myself, my best result is that there is only one graph in the program resources, that is, the desktop icon, of course, it's just an ideal state. For general applications, there are still some special icons or the effects that are hard to achieve, you need to use a cut graph.

However, as a developer, I feel that we should minimize the dependence on the artist and the cut graph.

One of my favorite ideas:

No design is the best design.


2. Extract tool classes unrelated to program logic:

BitmapUtils, Toast, log, and time tools follow the Top principle: tool classes irrelevant to the program business logic are extracted to the lib project.

When a project is completed, you will not only gain experience in business processing, but also have a powerful tool library. The improvement of your programming experience and philosophy can make your architecture more reasonable when creating a new project, the extraction of tools allows you to start a new project without repeating the low-end repetitive work, you have basic class libraries. You only need to focus on the business logic of the program. You only need to focus on the business of the program. What is the difference between the business of the program and the previous one.



In short, after the project is restructured, the ideal status is:

In the main project of the project, the resources and tool classes are inherited from the basic lib project, but only related to the project, all basic resources and tool classes unrelated to the interface style of the program business logic program are in the Lib project. Reduce repetitive work, reduce dependence on the cut chart, and extract basic resources. The main project only focuses on the business logic.


Not complete .....

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.