Java语言编程规范——命名规范

刚接触Android的时候,命名都是按照拼音来,所以有的时候想看懂命名的那个控件什么是什么用的,就要读一遍甚至好几遍才知道,这样的话,在代码的审查和修改过程中就会浪费不少不必要的时间。
如果就是我一个人开发,一个人维护的话还好,可是如果一个项目是团队分工合作,这样让你的同事去看你的代码就更加吃力了,因为大家之间的编程方式不一样,所以,在开发过程中,命名规范统一尤为重要,最好是团队中统一好大家命名方法,这样对于日后的工作会轻松很多。
在面试的时候,审核一个程序员的编程水平的时候,命名规范也是一大标准,所以,下面我就总结下我从网上别人的经验和自己的感悟中收集总结的android命名规范,希望对大家有所帮助。
提醒:在命名规范的统一下,再加上注释,这样日后维护会高效快捷好多

  • 包名采用域后缀倒置的加上自定义的包名,采用小写字母。包名使用产品的名称加上模块的名称。
    格式:
    com.ruen.产品名.模块名称
    示例:
    体检报告action类 import com.ruen.health.action.ExamReportAction;
    用户信息实体类 import com.ruen.health.bean.UserInfo;

  • 类名和接口使用类意义完整的英文描述,每个英文单词的首字母使用大写、其余字母使用小写的大小写混合法。
    示例:OrderInformation, CustomerList, LogManager, LogConfig

  • 方法名使用类意义完整的英文描述:第一个单词的字母使用小写、剩余单词首字母大写其余字母小写的大小写混合法。
    示例:

private void calculateRate();
public void addNewOrder();
  • 属性名使用意义完整的英文描述:第一个单词的字母使用小写、剩余单词首字母大写其余字母小写的大小写混合法。属性名不能与方法名相同。
    示例:
private customerName;
private orderNumber;
private smpSession;
  • 常量名使用全大写的英文描述,英文单词之间用下划线分隔开,并且使用 final static 修饰。
    示例:
public final static int MAX_VALUE = 1000;
public final static String DEFAULT_START_DATE = "2001-12-08";
  • 属性名可以和公有方法参数相同,不能和局部变量相同,引用静态成员变量时使用类名引用。
    示例:
public class Person
{
    private String name;
    private static List properties;

    public void setName (String val)
    {
        name = val;
    }

    public void setProperties (List val)
    {
        Person.properties = val;
    }
}

####建议
- 常用组件类的命名以组件名加上组件类型名结尾。
示例:
Action类型的,命名以Action结尾——ExamReportAction
Application 类型的,命名以App 结尾——MainApp
Frame 类型的,命名以Frame 结尾——TopoFrame
Panel 类型的,建议命名以Panel 结尾——CreateCircuitPanel
Bean 类型的,建议命名以Bean 结尾——DataAccessBean
EJB 类型的,建议命名以EJB 结尾——DBProxyEJB
Applet 类型的,建议命名以Applet 结尾——PictureShowApplet

  • 如果函数名超过15 个字母,可采用以去掉元音字母的方法或者以行业内约定俗成的缩写方式缩写函数名。
    示例:getCustomerInformation() 改为 getCustomerInfo()

  • 准确地确定成员函数的存取控制符号,不是必须使用 public 属性的,请使用 protected,不是必须使用 protected, 请使用 private。
    示例:protected void setUserName(), private void calculateRate()

本文作者:Rance935本文出处:Java语言编程规范——命名规范转载请在开头注明作者详细信息和本文出处
欢迎关注我的微信公众号和QQ群,分享Android 开发和互联网内容
Android技术分享:群号534813930
微信号:androidparks
公众号:AndroidParks

评论

  • Grupo Serval presídios回复

    What's up Dear, are you truly visiting this web site on a regular basis, if so after that you will absolutely get fastidious experience.|

  • Pool Fence回复

    Hey There. I found your blog using msn. This is an extremely well written article. I’ll make sure to bookmark it and return to read more of your useful info. Thanks for the post. I will definitely comeback.

  • Education Games回复

    Great beat ! I would like to apprentice while you amend your web site, how can i subscribe for a blog site? The account aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast provided bright clear concept

  • Farmgirl Flowers回复

    Great ¡V I should definitely pronounce, impressed with your website. I had no trouble navigating through all the tabs and related info ended up being truly simple to do to access. I recently found what I hoped for before you know it in the least. Reasonably unusual. Is likely to appreciate it for those who add forums or anything, web site theme . a tones way for your client to communicate. Nice task..

  • Laboratorium回复

    Hi, i think that i saw you visited my weblog thus i came to “return the favor”.I am trying to find things to enhance my site!I suppose its ok to use a few of your ideas!!

  • Busy At Home回复

    of course like your web site but you have to check the spelling on several of your posts. Many of them are rife with spelling problems and I in finding it very troublesome to inform the reality then again I¡¦ll surely come again again.

  • arts media回复

    Whats Happening i am new to this, I stumbled upon this I've found It positively helpful and it has aided me out loads. I am hoping to give a contribution & aid other customers like its helped me. Good job.

  • MakritskayaGergo回复

    viagra fa effetto

    <a href=http://viagraoail.com/>buy generic viagra</a>

    <a href="http://viagraoail.com/">online viagra</a>

    only now cheepest viagra

  • CheplanovaGergo回复

    where should i buy my viagra

    http://viagralms.com/ - buy generic viagra

    <a href="http://viagralms.com/">viagra cheap</a>

    what if i take two viagras

  • Growing With Plants回复

    Great article and right to the point. I don't know if this is truly the best place to ask but do you people have any ideea where to get some professional writers? Thanks 😊

  • wedding photography回复

    It is actually a great and helpful piece of information. I am satisfied that you simply shared this helpful information with us. Please keep us informed like this. Thanks for sharing.