"Alibaba Development Manual" reading notes (1)

6. [Mandatory] The name of the abstract class starts with Abstract or Base ; the name of the exception class ends with Exception ; the test class

The naming starts with the name of the class it is testing and ends with Test .


8. [Mandatory] Do not add is to any Boolean variable in POJO class , otherwise some framework parsing will cause serialization errors. Counter example: the attribute defined as the basic data type boolean isSuccess ;, its method is also isSuccess() , when the RPC framework is in reverse parsing, it " thinks " that the corresponding attribute name is success , so that the attribute cannot be obtained, and an exception is thrown.


often.


11. [Recommended] If a design pattern is used, it is recommended to reflect the specific pattern in the class name.
Description: The design pattern is reflected in the name, which is helpful for readers to quickly understand the architectural design idea.
Positive example: public class OrderFactory;
public class LoginProxy;

public class ResourceObserver;


12. [Recommended] Do not add any modifiers ( and do not add public ) to the methods and properties of the interface class , 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 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 " ; Negative example: Interface method definition: public abstract void f(); Explanation: In JDK 8 , the interface is allowed to have a default implementation, then this The default method is a default method that is valuable to all implementing classes






recognized to be realized.


15. [Reference] Naming conventions for each layer:
A) Service / DAO layer method naming convention
1 ) The method of obtaining a single object is prefixed with get . 2 ) The method of obtaining multiple objects is prefixed with list . 3 ) The method of obtaining the statistical value is prefixed with count . 4 ) The insert method is prefixed with save ( recommended ) or insert . 5 ) The delete method is prefixed with remove ( recommended ) or delete . 6 ) The modified 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 be named xxxPOJO .


2.1 1. [Mandatory] No magic value ( i.e. undefined constant ) is allowed to appear directly in the code.
Counter example: String key = " Id # taobao _" + tradeId ;

cache.put(key, value);


2.5 5. [Recommended] Use the Enum class if the variable value only changes within a range . If there is an extension attribute other than the name, the Enum class must be used . The number in the positive example below is the extension information, indicating the day of the week. Positive example: public Enum { MONDAY( 1 ) , TUESDAY( 2 ) , WEDNESDAY( 3 ) , THURSDAY( 4 ) , FRIDAY( 5 ) , SATURDAY( 6 ) , SUNDAY( 7 ); }




3.5 5. [Mandatory] Use 4 spaces for indentation, and tab characters are prohibited . Note: If you use tab indentation, you must set 1 tab to 4 spaces . When IDEA sets tab to 4 spaces,

Do not check Use tab character ; in eclipse , you must check insert spaces for tabs .


3.6 6. [Mandatory] The number of characters in a single line does not exceed 120. If it exceeds the limit, a new line is required. Follow the following principles when wrapping a line:
1 ) The second line is indented by 4 spaces relative to the first line, starting from the third line and no longer indenting Go ahead, refer to the example.
2 ) The operator wraps with the following.
3 ) The dot notation of the method call wraps with the following text.
4 ) When multiple parameters are too long, a line break is performed after the comma.
5 ) Do not wrap before parentheses, see counter example.
Positive example:
StringBuffer sb = new StringBuffer();
// In the case of more than 120 characters, the newline is indented by 4 spaces, and the dot before the method is wrapped together
sb.append("zi").append("xin" )...
        .append("huang")...
        .append("huang")...
        .append("huang");


3.8 8. [Mandatory] The text file encoding of the IDE is set to UTF -8 ; the newline character of the file in the IDE is in Unix format, not windows format.


4.1 1. [Mandatory] Avoid accessing the static variables or static methods of this class through the object reference of a class, which increases the compiler's parsing
cost , and
can be accessed directly by the class name .


4.3 3. [Mandatory] The same parameter type and the same business meaning can only use Java 's variable parameters and avoid using Object .
Description: Variable parameters must be placed at the end of the parameter list. ( Advocates students not to use variable parameter programming as much as possible )
Positive example: public User getUsers(String type, Integer... ids)


4.44. 【强制】对外暴露的接口签名,原则上不允许修改方法签名,避免对接口调用方产生影响。接
口过时必须加@
Deprecated 注解,并清晰地说明采用的新接口或者新服务是什么。


4.55. 【强制】不能使用过时的类或方法====》本人注:本条已在java10中得到禁止,否则后果很严重


4.77. 【强制】所有的相同类型的包装类对象之间值的比较,全部使用 equals 方法比较。
说明: 对于 Integer var=?-128 127 之间的赋值, Integer 对象是在
IntegerCache.cache 产生,会复用已有对象,这个区间内的 Integer 值可以直接使用==进行
判断,但是这个区间之外的所有数据,都会在堆上产生,并不会复用已有对象,这是一个大坑,

推荐使用 equals 方法进行判断。


4.88. 【强制】关于基本数据类型与包装数据类型的使用标准如下:
1所有的 POJO 类属性必须使用包装数据类型。
2RPC 方法的返回值和参数必须使用包装数据类型。
3所有的局部变量【推荐】 使用基本数据类型。
说明: POJO 类属性没有初值是提醒使用者在需要使用时,必须自己显式地进行赋值,任何
NPE 问题,或者入库检查,都由使用者来保证。
正例: 数据库的查询结果可能是 null,因为自动拆箱,用基本数据类型接收有 NPE 风险。
反例: 比如显示成交总额涨跌情况,即正负 x%x 为基本数据类型,调用的 RPC 服务,调用
不成功时,返回的是默认值,页面显示:
0%,这是不合理的,应该显示成中划线-。所以包装
数据类型的
null 值,能够表示额外的信息, 如:远程调用失败,异常退出。





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325849323&siteId=291194637