naming convention


1. [Mandatory] The names in the code cannot start with underscore or dollar sign , nor can they end with underline or dollar sign.

Counterexample: _name / __name / $Object / name_ / name$ / Object$

2. [Mandatory] Naming in the code is strictly prohibited Use a mixture of Pinyin and English, and direct use of Chinese is not allowed.

Note: Correct English spelling and grammar can make it easy for readers to understand and avoid ambiguity. Note that even the pure pinyin naming method should be avoided.

Counter example: DaZhePromotion [Discount] / getPingfenByName() [Rating] / int A certain variable = 3

Positive Example: alibaba / taobao / youku / hangzhou and other internationally common names can be regarded as the same as English.

3. [Mandatory] The class name must use UpperCamelCase style and must comply with camel case, with the following exceptions: (related naming of domain model) DO / BO / DTO / VO, etc.

Positive example: MarcoPolo / UserDO / XmlService / TcpUdpDeal / TaPromotion

Counter example: macroPolo / UserDo / XMLService / TCPUDPDeal / TAPromotion

4. [Mandatory] Method names, parameter names, member variables, and local variables all use lowerCamelCase style and must follow the camel case format.

Positive example: localValue / getHttpMessage() / inputUserId

5. [Mandatory] Constant names should be in all capital letters, and words should be separated by underscores to achieve semantic meaning. Express it completely and clearly, and don’t think your name is too long.

Positive example: MAX _ STOCK _ COUNT

Counterexample: MAX _ COUNT

6. [Mandatory] Abstract class The name starts with Abstract or Base; the name of the exception class ends with Exception; the name of the test class starts with the name of the class it is to test and ends with Test.

7. [Mandatory] Square brackets are part of the array type. The array is defined as follows: String[] args;

Counter example: Do not use String args[] to define.

8. [Mandatory] Do not add is to any Boolean type variable in the POJO class, otherwise some framework parsing will cause serialization errors.

Counter example: is defined as an attribute of the basic data type boolean isSuccess; its method is also isSuccess(). When the RPC framework performs reverse parsing, the attribute name corresponding to "for" is success, resulting in the attribute not being obtained, and then throwing an exception

.

9. [Mandatory] Package names must be in lowercase, and there must be one and only one English word with natural semantics between dot separators. Package names always use the singular form , but if the class name has a plural meaning, the class name can use the plural form.

Positive example: The application tool class package is named com . alibaba . open . util and the class name is MessageUtils (this rule refers to the framework structure of spring)

10. [Mandatory] Avoid completely non-standard abbreviations to avoid confusing the meaning of the text.

Counter example: The "abbreviation" of AbstractClass is named AbsClass; the "abbreviation" of condition is named condi. Such arbitrary abbreviation seriously reduces the readability of the code.

11. [Recommendation] If design patterns are used, it is recommended to reflect the specific patterns in the class name.

Note: Reflecting the design pattern in the name will help readers quickly understand the architectural design ideas.

Positive example: public class OrderFactory;

public class LoginProxy;

public class ResourceObserver;

12. [Recommended] Do not add any modification symbols to the methods and properties in the interface class (also do not add public), keep the code concise , and add valid Javadoc comments. Try not to define variables in the interface. If you must define variables, they must be related to the interface methods and are the basic constants of the entire application.

Positive example: Interface method signature: void f();

Interface basic constant representation: String COMPANY = " alibaba " ;

Counter example: Interface method definition: public abstract void f();

Explanation: Interfaces in JDK 8 allow defaults Implementation, then this default method is the default implementation that is valuable to all implementation classes.

13. There are two sets of rules for naming interfaces and implementation classes:

1) [Mandatory] For Service and DAO classes, based on the concept of SOA, the exposed services must be Interface, the internal

implementation class is distinguished from the interface by the suffix of Impl.

Positive example: CacheServiceImpl implements the CacheService interface.

2) [Recommendation] If it is an interface name that describes capabilities, use the corresponding adjective as the interface name (usually in the form of – able).

Positive example: AbstractTranslator implements Translatable.

14. [Reference] It is recommended to add the Enum suffix to the enumeration class name. The names of the enumeration members need to be in all uppercase letters, and the words should be separated by underscores.

Note: Enumeration is actually a special constant class, and the constructor is forced to be private by default.

Positive example: Enumeration name: DealStatusEnum, member name: SUCCESS / UNKOWN _ REASON.

15. [Reference] Naming convention for each layer:

A) Service / DAO layer method naming convention

1) Methods to obtain a single object are prefixed with get.

2) Methods to obtain multiple objects are prefixed with list.

3) The method of obtaining statistical values ​​is prefixed with count.

4) The insertion method is prefixed with save (recommended) or insert.

5) The deletion method is prefixed with remove (recommended) or delete.

6) The modification method is prefixed with update.

B) Domain model naming convention

1) Data object: xxxDO, xxx is the name of the data table.

2) Data transfer object: xxxDTO, xxx is the name related to the business field.

3) Display object: xxxVO, xxx is generally the name of the web page.

4) POJO is the collective name of DO / DTO / BO / VO, and it is forbidden to name it xxxPOJO.