"Android" Android development specifications a little bit of the experience

Source: Internet
Author: User

Because of the Java object-oriented programming features, you should choose nouns when naming

1, only one xxxapplication extends application, initialize global variables, Android use application summary

2. All xxxactivity extends Baseactivity, (Baseactivity extends activity) Initializes all the global variables and methods used by the activity.

3. All xxxfragment extends Basefragment, (Basefragment extends Fragment) Initialize all the global variables and methods used by Fragment.

4. All Xxxdbhelper extends Sqlitehelper, (Sqlitehelper extends Sqliteopenhelper) Initialize all the global variables and methods used by Sqliteopenhelper.

4. Method naming: A method represents a behavior that represents an action, the first word of the method name should be a verb, and the first letter is lowercase, and the first letter of each word is capitalized.

Property method: Starts with Get/set, followed by the field name, with the first letter of the field name capitalized. such as: GetUserName ()

Each method is only 10 lines, you can approach the method set.

5, interface naming: Xxxable, such as: interface class: Userinterface.java interface implementation class: Userinterfaceimp

6, the use of the Hump: Big Hump (Pascal): All single words of the first capital letter or each single word of the first letter are capitalized, for example: MyFirstName, Mylastname, commonly used for class names, Function name, property, namespace.

Small Hump (Chamel): The first word starts with a lowercase letter, the first uppercase of the second single word , or the first letter of each single word is capitalized, for example: MyFirstName, Mylastname.

Add: Use is to name the logical variable.

7, the constant name: all uppercase, between words plus "_".

8, note: Java In addition to the use of our common notation (//,/*/), the Java language Specification also defines a special note,

That is what we call Javadoc annotations, starting with/**, and ending with */, Javadoc annotations can be automatically converted to online documents, eliminating the hassle of writing program documents separately. Recommended use.

Javadoc annotations mainly cover the scope: classes, properties, methods.

Other people's Understanding:

Interface:

Use hump-style naming. In addition to nouns, you can also use adjectives to name (reflect their functional characteristics)

Method:

The rule is named after the verb, which is suitable for the hump type, but the biggest difference from the class name is that the first letter must be lowercase

Variable:

Rules are nouns, and others are named in the same way as "method". Variable names are critical, should be meaningful and easy to understand, and generally do not allow the use of a single letter for variable names. Except for some temporary variables, such as counters used in loops. When you use a single letter to make a variable name, I, J, and K are used to name the shaping variable.

Constant:

All uppercase letters indicate that if the name must be expressed in more than one word, the words are separated by "-". Constant requirements must be meaningful and can express the meaning of constants.

"Android" Android development specifications a little bit of the experience

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.