Naming rules for Android development and android Development
Identifier name Method
There are four types of identifiers:
1 Camel naming method: Also known as Camel naming method, the first letter of all other words except the first word is capitalized.
2 Pa pascal (pascal) naming method: Also known as the big camper naming method, the first letter of all words in uppercase
3. Underline naming: Separate words with underscores.
4 Hungary naming: This method is widely used in Microsoft programming environments. The variable type is described by appending a lower-case sequence before the variable in Pascal naming. The naming method of quantity is: <scope _> + <prefix _> + <qualifier> range prefix, type prefix, and qualified word.
I personally think that the identifier naming principle: use as few characters as possible to fully express the meaning of the identifier.
Abbreviations:
1 short words can be abbreviated by removing the "vowel"
2. The first few letters of a long word can be abbreviated.
3. There are also some common abbreviations of English words.
The following are common abbreviations:
Name |
Abbreviations |
Icon |
Ic (mainly used in app icons)
|
Color |
Cl (mainly used for color values)
|
Divider |
Di (mainly used for separation line, including not only divider in Listview, but also line in normal layout) |
Selector
|
Sl (mainly used for multiple States of a view, including not only selector in Listview, but also selector of buttons) |
Average |
Avg |
Background |
Bg (mainly used for la S and sub-la S) |
Buffer |
Buf |
Control |
Ctrl |
Delete
|
Del |
Document
|
Doc |
Error
|
Err |
Escape
|
Esc |
Increment
|
Inc |
Infomation
|
Info |
Initial
|
Init |
Image
|
Img |
Internationalization
|
I18N |
Length
|
Len |
Library
|
Lib |
Message
|
Msg |
Password-
|
Pwd |
Position
|
Pos |
Server
|
Srv |
String
|
Str |
Temp
|
Tmp |
Window
|
Wnd (win) |
The abbreviation principle is used in the program: Do not use the abbreviation unless it is customary.
Naming rules:
Packages: Uses anti-Domain Name naming rules and uses lowercase letters. The first-level package name is com, the second-level package name is xx (can be a company or an individual's casual), the third-level package name is based on the application name, and the fourth-level package name is module name or level name.
Package name |
This package contains |
Com. xx. Application name abbreviation. activities |
Activity Class used on the page (activities level Name User Interface Layer)
|
Com. xx. Application name abbreviation. base |
Each Activity class on the page can be written as an I-amount BaseActivity class (basic shared class) |
Com. xx. Application name abbreviation. adapter |
Page Adapter class (Adapter class) |
Com. xx. Application name abbreviation. tools
|
This package includes: Public tool method class (tool module name) |
Com. xx. Application name abbreviation. bean (or com. xx. Application name abbreviation. unity) |
This package includes: Element class |
Com. xx. Application name abbreviation. db |
Database Operations |
Com. xx. Application name abbreviation. view (or com. xx. Application name abbreviation. ui) |
Custom View class |
Com. xx. Application name abbreviation. service |
Service |
Com. xx. Application name abbreviation. broadcast
|
Broadcast Service |
Class 2 (classes): a noun that uses the big camper method to avoid abbreviations unless the abbreviation is well known, such as HTML and URL. If the class name contains a word abbreviation, each letter of the abbreviation should be capitalized.
Class |
Description |
For example |
Activity Type |
Aty or Activity is a suffix |
Welcome Page class WelcomeAty. Or WelcomeActivity |
Adapter class |
Adp or Adapte is a suffix |
News details adapter NewtDetailAdp or NewDetailAdapter |
Resolution class |
Hlr is a suffix identifier |
HomePosterHlr |
Common Methods |
Tools or Manager is a suffix |
Thread Pool Management class: ThreadPoolManager Log tool: LogTools |
Database |
Marked with the DBHelper suffix |
News Database: NewDBHelper |
Service |
Marked with a Service extension |
Time Service TimeService |
BroadcastReceive class |
ID with Broadcast as the suffix |
Time notification TimeBroadcast |
ContentProvider |
ID with Provider suffix |
|
Shared basic classes written directly |
Starting with Base |
BaseActivity, BaseFragment |
3 interface: Like a class, the naming rule uses the big camper method and ends with able or visible, such as interface Runna ble;
Interface Accessible.
Method 4 (methods): a verb or a noun. The method of using a small camper is called onCreate () and run ()
Method |
Description |
InitXX () |
Initialize related methods and use init as the prefix, such as initializing the layout of initView () |
IsXX () |
If the checkXX () method returns a boolean value, use is or check as the prefix. |
GetXX () |
Returns a value using the get prefix. |
ProcessXX () |
To process data, use process as the prefix. |
DisplayXX () |
A prompt box and prompt message are displayed, marked with the prefix "display ". |
SaveXX () |
Id related to data storage using sav as the e prefix |
ResetXX () |
For data restructuring, use the reset prefix to identify |
ClearXX () |
Clear data-related |
RemoveXXX () |
Clear data-related |
DrawXXX () |
Used to identify data or effects based on the draw prefix. |