Alibaba Java Development Manual-code writing specification and attention __java

Source: Internet
Author: User
Tags constant definition manual lowercase

Concepts of VO, PO, do, DTO, BO, QO, DAO, Pojo in Java PO (Persistant object) Persistent object

The concept of the O/R mapping occurs when there is no O/R mapping, and no such concept exists. Usually the corresponding data model (database), itself also has some business logic processing. Can be seen as a Java object mapped to a table in a database. The simplest PO is a record in a table in the corresponding database, and multiple records can be set with a PO. The PO should not contain any operations on the database. Do (domain object) domain object

is a tangible or intangible business entity abstracted from the real world. Generally corresponds to the table structure in the data. to (Transfer object), data transfer object

Object DTO (data Transfer object) data Transfer object transmitted between applications with different tie (relationship)

This concept derives from the Java EE design pattern, which is designed to provide coarse-grained data entities for EJB distributed applications to reduce the number of distributed calls, thereby increasing the performance of distributed calls and reducing network load, but here I refer to the data transfer object between the presentation layer and the service layer. VO (View object) value Object

A View object, used for the presentation layer, that encapsulates all the data for a specified page (or component). BO (Business object) business Object

See the domain object in the UML component Domain model from the perspective of the business model. A Java object that encapsulates business logic, which is combined with PO,VO to perform business operations by invoking the DAO method. Business object: The primary role of business objects is to encapsulate business logic as an object. This object can include one or more other objects. such as a resume, education experience, work experience, social relations and so on. We can put the education experience corresponding to a PO, work experience corresponding to a PO, social relations corresponding to a PO. Create a resume of the Bo object to process the CV, each Bo contains these PO. This way, when dealing with business logic, we can deal with BO. POJO (Plain ordinary Java object) simple, irregular Java objects

Pure traditional Java objects. That is, in some object/relation Mapping tools, the Persisent object, which is capable of maintaining database table records, is a pure Java object that conforms to the Java Bean specification and does not add other properties and methods. My understanding is that the most basic Java beans, only property fields and setter and Getter methods ... DAO (data Access object)

is a sun-standard Java EE design pattern in which an interface is a DAO, which negatively operates on a persistent layer. Provides interfaces for the business layer. This object is used to access the database. Commonly used in conjunction with PO, DAO contains a variety of database operation methods. Through its method, combine the PO to carry on the related operation to the database. Sandwiched between business logic and database resources. Cooperate with VO to provide CRUD operations for the database


I. Programming protocol
(i) Naming style
1. The name in the "mandatory" code cannot begin with an underscore or dollar sign, or end with an underscore or dollar sign.
Anti-Example: _name/__name/$name/name_/name$/name__
2. The naming in "mandatory" code prohibits the use of pinyin in combination with the English language, and is not allowed to use Chinese directly.
Description: Correct English spelling and grammar can make reading readers easy to understand and avoid ambiguity. Note that even if the pure phonetic naming method
should also avoid adoption.
Positive example: Alibaba/taobao/youku/hangzhou and other international common name, visual and English.
Counter example: dazhepromotion [discount]/Getpingfenbyname () [rating]/int a variable = 3
3. The "Coercion" class name uses Uppercamelcase style, except in the following cases: Do/bo/dto/vo/ao/
PO and so on.
Positive example: marcopolo/userdo/xmlservice/tcpudpdeal/tapromotion
Anti-Example: macropolo/userdo/xmlservice/tcpudpdeal/tapromotion
4. "Mandatory" method name, parameter name, member variable, local variable all uniform use Lowercamelcase style, must comply with
Hump form.
Positive example: Localvalue/gethttpmessage ()/Inputuserid
5. "Mandatory" constant name all uppercase, the words are separated by an underscore, to achieve the semantic expression of complete and clear, not too long name.
Positive example: Max_stock_count
Anti-Example: Max_count
6. "Force" abstract class naming begins with abstract or Base; Exception class naming uses Exception end; test class
Name begins with the class name that it wants to test, ending with test.
7. The "coercion" type defines an array as it is closely connected to the brackets.
In the positive example: define the plastic array int[] Arraydemo;
Anti-Example: in the main argument, use String args[] to define.
8. "Force" POJO variables of the Boolean type in the class without the is prefix, or some of the framework parsing can cause serialization errors.
Anti-Example: a property defined as a Boolean isdeleted of the base data type, and its method is isdeleted (), RPC
Alibaba Java Development Manual
2/36
When the framework is in reverse parsing, the "mistaken" attribute name is deleted, resulting in the property is not obtained, and then thrown
An exception.
9. "Mandatory" package name unified use lowercase, dot delimiter between there is and only a natural semantics of English words. Package Name Unified Use
Singular form, but if the class name has a plural meaning, the class name can be in the plural form.
Example: The utility class package name is Com.alibaba.ai.util and the class name is messageutils (this rule references spring
Frame structure)
10. "Mandatory" to eliminate the complete irregular abbreviations, to avoid the hope that the text does not know righteousness.
Anti-Example: abstractclass "abbreviation" is named Absclass; condition "abbreviation" is named Condi, this class follows
The acronym severely reduces the readability of the code.
11. "Recommended" in order to achieve the goal of code interpretation, any custom programming elements in the name, use as complete as possible words
Combination to express their meaning.
In the example: the class that pulls the substitution code from the remote warehouse is named Pullcodefromremoterepository.
Counter example: variable int A; The random naming method.
12. "Recommended" if modules, interfaces, classes, methods use the design pattern, in the name of the specific pattern.
Description: The design pattern is embodied in the name, which helps the reader to understand the architecture design concept quickly.
Positive example: public class orderfactory;
public class Loginproxy;
public class Resourceobserver;
13. Methods and properties in the "recommended" interface class do not add any modifiers (public or not) to keep the code simple
and add a valid Javadoc annotation. Try not to define variables in the interface, and if you have to define variables, you must be
is associated with an interface method and is the underlying constant for the entire application.
Positive example: interface method signature void f ();
Interface Base constant String company = "Alibaba";
Anti-Example: interface method defines public abstract void f ();
Note: The JDK8 interface allows for a default implementation, and this default method is a value for all implementation classes of the implied
Realize.
14. Interfaces and implementation classes are named with two sets of rules:
1 "coercion" for service and DAO classes, based on the SOA concept, the exposed services must be interfaces, internal
The implementation class uses the Impl suffix and the interface difference.
In the positive example: Cacheserviceimpl implements the Cacheservice interface.
2 "recommended" If the interface name is descriptive, take the corresponding adjective as the interface name (usually in the form of –able).
Positive example: Abstracttranslator realizes translatable.
Alibaba Java Development Manual
3/36
15. The "Reference" enumeration class name is recommended with the enum suffix, the enumeration member names need to be all uppercase, and the words are separated by an underscore.
Description: Enumerations are actually special constant classes, and the constructor method is private by default.
In the positive example: enumerate the member names named Processstatusenum: Success/unknown_reason.
16. Naming conventions for "reference":
A) Service/dao layer method naming protocol
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 statistic value is prefixed with count.
4 the insertion method is prefixed with Save/insert.
5 The method of deletion is prefixed with remove/delete.
6) The modified method is prefixed with update.
(B) domain model naming conventions
1 data object: Xxxdo, XXX is the data table name.
2 Data Transmission object: Xxxdto, XXX is the name of the business domain.
3 Display object: Xxxvo, XXX General for Web page name.
4) POJO is a general designation of DO/DTO/BO/VO, which is forbidden to be named Xxxpojo.
(ii) Constant definition
1. "Coercion" does not allow any magical value (i.e., without predefined constants) to appear directly in the code.
Anti-Example: String key = "Id#taobao_" + TradeID;
Cache.put (key, value);
2. "Force" long or long when the initial assignment, the use of uppercase L, can not be lowercase l, lowercase easily with the number 1 mixed
Xiao, causing misunderstanding.
Description: Long a = 2l; Is that a 21 of the number or a Long type of 2?
3. "Recommended" do not use a constant class to maintain all constants, according to the constant function of the classification, separate maintenance.
Description: All-Inclusive constant class, it is necessary to use the lookup function to navigate to the modified constants, not conducive to understanding and maintenance.
Positive example: Cache-related constants are placed under Class cacheconsts, and system configuration-related constants are placed under Class configconsts.
4. The reuse level of the "recommended" constant has five layers: shared constants across applications, shared constants within applications, shared constants in sub-projects, packages
Shared constants within the class, shared constants within the classes.
1 shared constants across applications: placed in two-party libraries, usually in the constant directory in Client.jar.
2 Application-Shared constants: placed in one library, usually in a constant directory in a child module.
Anti-Example: easy to understand variable also to be defined as the application of shared constants, two of the siege in two classes defined the representation
"Yes" variable:
Class A: public static final String Yes = "yes";
Alibaba Java Development Manual
4/36
Class B: public static final String YES = "

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.