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

评论

  • Umanizzare Gestão Prisional Ltda回复

    When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get several e-mails with the same comment. Is there any way you can remove me from that service? Appreciate it!|

  • MakritskayaGergo回复

    viagra in farmacia propeci

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

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

    spain female viagra

  • CheplanovaGergo回复

    kann gunstig viagra bestellen

    http://viagralms.com/ - online viagra

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

    viagra ninos

  • website laten maken回复

    I like what you guys are usually up too. This type of clever work and reporting!
    Keep up the very good works guys I've included you guys to blogroll.

  • Continuing Education回复

    I loved as much as you'll receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get got an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly very often inside case you shield this hike.

  • Legal Aid Society回复

    Thanks for another fantastic post. Where else could anybody get that kind of info in such a perfect manner of writing? I have a presentation next week, and I am on the look for such information.

  • CheplanovaGergo回复

    100mg viagra too much

    http://viagralms.com/ - viagra cheap

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

    effet viagra 50 mg

  • yeezy boost 350回复

    I just wanted to write down a quick note to say thanks to you for those remarkable suggestions you are giving out here. My considerable internet lookup has now been paid with excellent suggestions to share with my relatives. I would assume that many of us website visitors are truly blessed to dwell in a superb website with so many wonderful people with beneficial guidelines. I feel quite fortunate to have discovered your web page and look forward to really more enjoyable moments reading here. Thanks a lot once again for a lot of things.

  • Obat Gonore Resep Dokter回复

    Hеllo tօ evereу body, it's my first go tο see of this weblog;
    this wеblog carries ɑmazing and in fact good stuff for visitors.

  • VladilenGergo回复

    ordering viagra online illegal

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

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

    buy viagra in johor

  • Lelio Junior回复

    I will right away take hold of your rss feed as I can't to find your email subscription hyperlink or e-newsletter service. Do you have any? Please let me recognize so that I may just subscribe. Thanks.|

  • VladilenGergo回复

    hot sauce viagra

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

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

    levitra 20 mg o viagra

  • travel promo回复

    I loved as much as you'll receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get got an nervousness over that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly very often inside case you shield this hike.

  • Civil Law回复

    As I website possessor I believe the content matter here is rattling great , appreciate it for your hard work. You should keep it up forever! Best of luck.

  • Gardening回复

    Hey There. I found your blog using msn. This is an extremely well written article. I’ll be sure to bookmark it and come back to read more of your useful information. Thanks for the post. I will certainly comeback.

  • School Technology回复

    Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I acquire actually enjoyed account your blog posts. Any way I will be subscribing to your feeds and even I achievement you access consistently quickly.

  • park回复

    I precisely desired to say thanks once again. I'm not certain the things I could possibly have accomplished without the entire recommendations shared by you regarding such a topic. Entirely was the hard problem for me personally, but looking at your specialised style you resolved it made me to weep with delight. I'm happy for this support as well as wish you really know what a great job that you are carrying out instructing other individuals through your site. I am certain you've never met any of us.

  • AdamGergo回复

    cialis somniferes

    http://canadianiucialis.com/ - canadian cialis

    <a href="http://canadianiucialis.com/">cialis cheap</a>

    cialis difference in mg

  • Special Education回复

    I’m 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 great info I was looking for this info for my mission.

  • LenaGergo回复

    generic viagra tabs

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

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

    prix du viagra en algerie

  • Itamar Serpa Fernandes回复

    After going over a handful of the blog posts on your website, I honestly appreciate your way of writing a blog. I book marked it to my bookmark website list and will be checking back in the near future. Please visit my website as well and tell me how you feel.|

  • LenaGergo回复

    achat du viagra 50 mg

    <a href=http://norxcheapviagraf.com/>buy viagra online</a>

    <a href="http://norxcheapviagraf.com/">generic viagra</a>

    looking buy viagra online

  • longchamp回复

    Nice post. I learn something more difficult on different blogs everyday. It will always be stimulating to learn content material from different writers and practice a bit something from their store. I抎 desire to make use of some with the content material on my weblog whether or not you don抰 mind. Natually I抣l provide you with a hyperlink in your internet blog. Thanks for sharing.

  • AdamGergo回复

    discount soft cialis

    http://canadianiucialis.com/ - cialis online

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

    cialis horror stories

  • Dress and Skirts回复

    Well I sincerely liked studying it. This article provided by you is very helpful for proper planning.

  • Fragrance skin care回复

    Nice post. I was checking continuously this blog and I'm impressed! Extremely useful info specifically the last part 😊 I care for such info a lot. I was looking for this certain information for a very long time. Thank you and best of luck.

  • Kid's room home design回复

    Whats Going down i'm new to this, I stumbled upon this I have found It absolutely helpful and it has aided me out loads. I'm hoping to give a contribution & help different customers like its aided me. Good job.

  • AdamGergo回复

    cialis prix reduit

    http://canadianiucialis.com/ - canadian cialis

    <a href="http://canadianiucialis.com/">buy cialis</a>

    compare generic cialis prices

  • further wireless回复

    I've been browsing online greater than three hours these days, yet I
    never discovered any fascinating article like yours.
    It is lovely value sufficient for me. In my view, if all webmasters and bloggers made
    excellent content material as you probably did, the web will probably be much
    more useful than ever before.

  • Positive Parenting Techniques回复

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

  • Laptop Computers回复

    Generally I don't read article on blogs, however I wish to say that this write-up very compelled me to check out and do so! Your writing taste has been amazed me. Thank you, very great post.

  • designer回复

    Wow, incredible blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is magnificent, as well as the content!

  • Motorcars回复

    Thanks for some other great article. The place else could anybody get that type of information in such a perfect method of writing? I have a presentation subsequent week, and I am on the search for such information.

  • Jose Wilame Araujo Rodrigues回复

    Fantastic beat ! I wish to apprentice at the same time as you amend your web site, how can i subscribe for a blog website? The account aided me a appropriate deal. I had been a little bit familiar of this your broadcast provided vivid clear idea|

  • Boots & booties回复

    Wonderful goods from you, man. I have understand your stuff previous to and you're just too wonderful. I actually like what you've acquired here, certainly like what you're stating and the way in which you say it. You make it entertaining and you still take care of to keep it smart. I can not wait to read far more from you. This is really a tremendous site.

  • Smart TVs回复

    Hello, i think that i saw you visited my blog thus i came to “return the favor”.I'm trying to find things to enhance my website!I suppose its ok to use a few of your ideas!!

  • Dinner for fitness回复

    What i don't realize is if truth be told how you're not really much more smartly-appreciated than you might be right now. You're so intelligent. You realize thus significantly relating to this matter, made me for my part consider it from a lot of numerous angles. Its like men and women are not involved except it¡¦s something to accomplish with Lady gaga! Your individual stuffs excellent. Always take care of it up!

  • Kid's room home design回复

    Thank you so much for providing individuals with an exceptionally memorable possiblity to check tips from here. It really is so good and also jam-packed with amusement for me personally and my office acquaintances to search the blog a minimum of three times a week to find out the new issues you will have. And lastly, I'm so always impressed with your powerful knowledge you serve. Some 4 areas in this posting are undeniably the very best we've had.

  • Hair Loss回复

    Great goods from you, man. I've understand your stuff previous to and you are just extremely fantastic. I actually like what you have acquired here, really like what you are stating and the way in which you say it. You make it enjoyable and you still care for to keep it sensible. I can't wait to read much more from you. This is really a tremendous site.

  • Shoes and Sandals回复

    I have been browsing online more than 3 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my opinion, if all website owners and bloggers made good content as you did, the net will be much more useful than ever before.

  • Earphones回复

    I¡¦ve been exploring for a little for any high-quality articles or weblog posts on this sort of space . Exploring in Yahoo I at last stumbled upon this site. Studying this info So i¡¦m glad to show that I've an incredibly just right uncanny feeling I came upon just what I needed. I so much indisputably will make certain to don¡¦t forget this web site and give it a look regularly.

  • Swimming Routines回复

    It¡¦s actually a cool and useful piece of information. I¡¦m glad that you just shared this helpful info with us. Please keep us up to date like this. Thanks for sharing.

  • Bathroom Remodeling Ideas回复

    Good blog! I really love how it is easy on my eyes and the data are well written. I am wondering how I could be notified when a new post has been made. I have subscribed to your RSS feed which must do the trick! Have a great day!

  • Massage skin care回复

    Excellent weblog right here! Also your web site so much up very fast! What web host are you the usage of? Can I am getting your affiliate link to your host? I desire my website loaded up as fast as yours lol

  • shopping tips回复

    I'm still learning from you, while I'm trying to achieve my goals. I definitely enjoy reading everything that is written on your site.Keep the aarticles coming. I liked it!

  • Single Mother Parenting回复

    I simply wanted to post a simple note to be able to thank you for some of the awesome concepts you are writing at this site. My time intensive internet search has now been rewarded with beneficial insight to exchange with my guests. I 'd point out that most of us website visitors actually are very lucky to live in a superb site with many awesome professionals with interesting strategies. I feel truly fortunate to have seen your web page and look forward to some more exciting minutes reading here. Thank you once again for a lot of things.

  • adidas ultra boost回复

    My spouse and i were now joyous Jordan managed to round up his researching because of the precious recommendations he gained out of your web pages. It is now and again perplexing to just always be freely giving things which often other folks could have been selling. We grasp we now have you to be grateful to because of that. These illustrations you made, the simple blog menu, the friendships you make it possible to create - it's mostly terrific, and it's really helping our son in addition to us believe that the concept is pleasurable, which is tremendously essential. Thanks for everything!

  • women dresses回复

    Hello very cool web site!! Guy .. Excellent .. Amazing .. I will bookmark your website and take the feeds also¡KI am glad to seek out a lot of helpful information right here within the publish, we'd like develop more strategies on this regard, thanks for sharing. . . . . .

  • Auto回复

    You are a very intelligent person!

  • Parenting Course回复

    Wow! This can be one particular of the most beneficial blogs We've ever arrive across on this subject. Basically Excellent. I am also a specialist in this topic therefore I can understand your effort.