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

评论

  • special education teacher回复

    magnificent post, very informative. I'm wondering why the other specialists of this sector do not realize this. You must continue your writing. I'm confident, you've a huge readers' base already!

  • casual dating回复

    It¡¦s actually a nice and useful piece of information. I am satisfied that you simply shared this helpful info with us. Please stay us up to date like this. Thanks for sharing.

  • medical school回复

    Hello. magnificent job. I did not anticipate this. This is a excellent story. Thanks!

  • cool gadgets回复

    Usually I do not learn article on blogs, however I wish to say that this write-up very pressured me to check out and do it! Your writing taste has been surprised me. Thanks, quite great post.

  • salmon recipe回复

    I am not sure where you're getting your info, but great topic. I needs to spend some time learning much more or understanding more. Thanks for fantastic info I was looking for this information for my mission.

  • drywall repair回复

    Unquestionably believe that which you stated. Your favorite justification appeared to be on the net the simplest thing to be aware of. I say to you, I certainly get irked while people think about worries that they just do not know about. You managed to hit the nail upon the top and defined out the whole thing without having side-effects , people could take a signal. Will likely be back to get more. Thanks

  • educational games for kids回复

    I do consider all the ideas you have presented on your post. They are very convincing and can definitely work. Nonetheless, the posts are too quick for starters. Could you please extend them a little from next time? Thank you for the post.

  • universalsitesupplies.co.uk回复

    I’m not sure where you are getting your information, but great topic. I needs to spend some time learning much more or understanding more. Thanks for magnificent info I was looking for this information for my mission.

  • AlenaGergo回复

    walgreens cialis at

    [url=http://buycialiskj.com/]generic cialis[/url]

    <a href="http://buycialiskj.com/">generic cialis online</a>

    cialis costs canada

  • universalsitesupplies.co.uk回复

    you're really a good webmaster. The website loading speed is amazing. It seems that you are doing any unique trick. In addition, The contents are masterwork. you have done a fantastic job on this topic!

  • GoloaGergo回复

    bodybuilding cialis dosage

    [url=http://canadianfdcialis.com/]cialis[/url]

    <a href="http://canadianfdcialis.com/">generic cialis online</a>

    cialis genericos 10mg

  • M88回复

    Hey there! I just wanted to ask if you ever have any issues with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no data backup. Do you have any methods to stop hackers?

  • universalsitesupplies.co.uk回复

    I am no longer sure the place you're getting your information, however great topic. I must spend a while finding out much more or understanding more. Thanks for fantastic info I used to be searching for this info for my mission.

  • universalsitesupplies.co.uk回复

    Unquestionably consider that that you stated. Your favorite justification appeared to be at the net the easiest factor to keep in mind of. I say to you, I certainly get annoyed while folks think about worries that they just do not understand about. You managed to hit the nail upon the highest and defined out the whole thing without having side effect , other folks can take a signal. Will likely be back to get more. Thanks

  • Dog Walker Ottawa回复

    Howdy! I know this is kinda off topic but I was wondering if you knew where I could locate a captcha plugin for my comment form? I'm using the same blog platform as yours and I'm having problems finding one? Thanks a lot!

  • dog training回复

    Hi! I know this is kinda off topic but I'd figured I'd ask. Would you be interested in trading links or maybe guest writing a blog post or vice-versa? My blog covers a lot of the same subjects as yours and I think we could greatly benefit from each other. If you might be interested feel free to send me an e-mail. I look forward to hearing from you! Superb blog by the way!|

  • Internet Marketing回复

    I have been absent for some time, but now I remember why I used to love this web site. Thank you, I will try and check back more frequently. How frequently you update your website?

  • adidas nmd r1回复

    Needed to post you this little word to finally say thanks the moment again with your striking information you have contributed in this case. This is quite extremely open-handed with people like you to present unhampered what exactly most people might have supplied as an electronic book in order to make some profit on their own, even more so considering that you might well have tried it if you decided. Those things as well acted as the good way to fully grasp other people online have the identical dreams really like my very own to realize a good deal more pertaining to this matter. I'm certain there are several more pleasurable times ahead for individuals who start reading your website.

  • Fastest Tehhnology回复

    Wow, wonderful blog format! How long have you ever been blogging for? you make running a blog look easy. The overall glance of your site is magnificent, let alone the content!

  • Business Finance回复

    Hello, Neat post. There's a problem along with your website in internet explorer, could test this¡K IE still is the marketplace leader and a large element of people will miss your excellent writing because of this problem.

  • justbedding.com.au回复

    It is actually a great and helpful piece of info. I’m satisfied that you just shared this useful info with us. Please keep us informed like this. Thanks for sharing.