|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
本人曾和一些同事一起做项目写代码,拿人家的代码过来很是头痛!
原因:一,代码里命名不规范;二不写注释!
命名规范方面
包命名要适当深一些,一般用公司或其他组织的域名的反向如:
com.eampub.app.userManage, com.qiler.entertainment.movie
类名应用英文名字为主,而且首字母大写,如果不只一个单词,第二个单词的手字母也应该大写,这就是所谓的“驼峰式“,如:Company 、 User、 UserAction 、UserForm 等等
工程名和变量名也用英文单词名词但第一个单词首字母不大写,从第二个单词开始首字母要大写,如 : user 、 userForm
方法名用英文动词,只有一个单词的不用任何字母大写,有两个和两个以上的第二个单词首字母大写,如:public void add(...){} 、public String getUserName(){return ...} 等
整体风格如下(本人写过的一个JavaBean):
package com.qiler.app.priceManage;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
public class PriceForm extends ActionForm {
private String description;
private Double hourPrice;
private Long id;
private Long[] ids;
private Double monthPrice;
private String name;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public void setName(String name) {
this.name = name;
}
public void setMonthPrice(Double monthPrice) {
this.monthPrice = monthPrice;
}
public void setIds(Long[] ids) {
this.ids = ids;
}
public void setId(Long id) {
this.id = id;
}
public void setHourPrice(Double hourPrice) {
this.hourPrice = hourPrice;
}
public Double getHourPrice() {
return hourPrice;
}
public Long getId() {
return id;
}
public Long[] getIds() {
return ids;
}
public Double getMonthPrice() {
return monthPrice;
}
public String getName() {
return name;
}
public ActionErrors validate(ActionMapping actionMapping,
HttpServletRequest httpServletRequest) {
/** @todo: finish this method, this is just the skeleton.*/
return null;
}
public void reset(ActionMapping actionMapping,
HttpServletRequest servletRequest) {
}
} |
|