Android programming Standard Guide
I. Directory Specification
1. System Directory Specification
Requirement: Requirement document; Design: Design document;
Planning & Log: Plan, Log, meeting;
Test: integration Test, system Test, and Test report;
Study: learning materials, demos, etc;
Deployment: Release and Deployment;
Source: Source Code and unit test;
Help: Related Help documents;
2. Source Code directory Specification
A directory is a package. All classes in the directory belong to this namespace, one main class and one file;
Directory hierarchy recursion; generally, the system namespace Directory should not exceed three layers;
Ii. Code coding specifications
1. common naming rules
Pascal naming method (Delphi): uppercase for each word;
Camel naming method (camel naming method): the first letter is lowercase, and the subsequent words are uppercase;
Hungary name (VB): uses a prefix to calibrate features and attributes, such as mName;
Underline naming: separated by underscores, such as constants;
2. Android naming features:
Package: all lower case;
File Name: the file name is the class name;
Class Name: (common class) pascal name method; (custom Attribute class) plus Attribute; (custom Exception class) plus Exception; (generic type transfer) K, T;
Method naming: pascal naming is used for constructors, camel naming is used for common functions, and verb-object phrases;
Interface Name: Generally, it is named with a suffix;
Variable name: (class) Private member variable (mMyName), Public variable, static variable (sMyName); local variable (camel); method parameter (camel ); loop Variable (meaningless letters );
Optimization: Partial Variables start with _ and parameter variables start with p;
3. format:
Strict line feed: One colon for one line; {} Each occupies one line;
Strict indentation: Tab indentation is used; indentation and code indentation are emphasized; strict notes: files, classes, methods, method parameters, variables, attributes; files and classes must contain the following elements: name, Description, Version, Date, Author, Change, Copyright;
Declaration position: similar imports can be put together, which can be very clear; member variables are placed at the beginning, preferably not interspersed; local variables are also placed before the local method;
Use java predefined types instead of class names to declare variables;
Iii. Code logic specifications
1. Avoid placing multiple classes in one file, unless they are internal classes for one-time use;
2. The code length of a method should not exceed 35 lines;
3. In principle, do not manually modify the code generated by the machine;
4. final String replaces the direct "String", which is the same as int;
5. Do not perform direct return operations in normal loop statements;
6. Do not use the goto statement;
7. consider exceptions everywhere, especially I/O operations. Perform try... catch operations more;
8. public is used only for public announcements, while private or internal is used for others;
9. do not provide public and protected program scalar as much as possible, and use attributes instead of them;
10. Do not directly run some business code on the functions automatically generated by the system. It is best to customize the functions and then call them;
11. It is always an excuse to use the display interface;
12. The default statement is always used to display information in the switch statement;