`
leonzhx
  • 浏览: 796770 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Item 56: Adhere to generally accepted naming conventions

阅读更多

1.  Loosely speaking, naming conventions fall into two categories: typographical and grammatical.

 

2.  Package names should be hierarchical with the components separated by periods. Components should consist of lowercase alphabetic characters and, rarely, digits. The name of any package that will be used outside your organization should begin with your organization’s Internet domain name with the top-level domain first. Users must not create packages whose names begin with java or javax. The remainder of a package name should consist of one or more components describing the package. Components should be short, generally eight or fewer characters. Meaningful abbreviations are encouraged.

 

3.  Class and interface names, including enum and annotation type names, should consist of one or more words, with the first letter of each word capitalized. Abbreviations are to be avoided, except for acronyms and certain common abbreviations. If multiple acronyms occur back-to-back, you can still tell where one word starts and the next word ends when you capitalize only the first letter of the acronyms.

 

4.  Method and field names follow the same typographical conventions as class and interface names, except that the first letter of a method or field name should be lowercase.

 

5.  A constant field is a static final field whose value is immutable, whose names should consist of one or more uppercase words separated by the underscore character.

 

6.  Local variable names have similar typographical naming conventions to member names, except that abbreviations are permitted, as are individual characters and short sequences of characters whose meaning depends on the context in which the local variable occurs.

 

7. Type parameter names usually consist of a single letter. Most commonly it is one of these five: T for an arbitrary type, E for the element type of a collection, K and V for the key and value types of a map, and X for an exception. A sequence of arbitrary types can be T, U, V or T1, T2, T3.

 

8. For quick reference, the following table shows examples of typographical conventions:



 

9.  There are no grammatical naming conventions to speak of for packages. Classes, including enum types, are generally named with a singular noun or noun phrase. Interfaces are named like classes, or with an adjective ending in able or ible.

 

10.  Because annotation types have so many uses, no part of speech predominates. Nouns, verbs, prepositions, and adjectives are all common.

 

11.  Methods that perform some action are generally named with a verb or verb phrase (including object). Methods that return a boolean value usually have names that begin with the word is or, less commonly, has, followed by a noun, noun phrase, or any word or phrase that functions as an adjective. Methods that return a non-boolean function or attribute of the object on which they’re invoked are usually named with a noun, a noun phrase, or a verb phrase beginning with the verb get. The form beginning with get is mandatory if the class containing the method is a Bean, and it’s advisable if you’re considering turning the class into a Bean at a later time. Also, there is strong precedent for this form if the class contains a method to set the same attribute.

 

12.  Methods that convert the type of an object, returning an independent object of a different type, are often called toType.

 

13.  Methods that return a view whose type differs from that of the receiving object are often called asType.

 

14.  Methods that return a primitive with the same value as the object on which they’re invoked are often called typeValue.

 

15.  Common names for static factories are valueOf, of, getInstance, newInstance, getType, and newType.

 

16.  Grammatical conventions for field names are less well established and less important than those for class, interface, and method names, as well-designed APIs contain few if any exposed fields. Fields of type boolean are often named like boolean accessor methods with the initial is omitted. Fields of other types are usually named with nouns or noun phrases.

 

17.  Grammatical conventions for local variables are similar to those for fields, but even weaker.

 

  • 大小: 29.1 KB
分享到:
评论

相关推荐

    Effective Java 3rd edition(Effective Java第三版英文原版)附第二版

    Item 68: Adhere to generally accepted naming conventions 10 Exceptions Item 69: Use exceptions only for exceptional conditions Item 70: Use checked exceptions for recoverable conditions and runtime ...

    Python for Informatics

    This includes guidelines on naming conventions, documentation, and performance optimization. #### Licensing and Distribution The book is licensed under a Creative Commons Attribution-NonCommercial-...

    历年英语六级必考高频核心词汇top500.doc

    例句:Adhere to your own principle. (坚持你自己的原则) 10. adverse(不利的,有害的):形容词,常用于描述对某人或某事有负面影响的情况。 例句:Adverse circumstances can test a person’s wisdom and ...

    英语四级700高频词汇(字母排序带音标)[精选.].doc

    4. adhere - 表示“粘附”或“遵守”,在法律、协议等语境中常指遵守规则,如:adhere to the contract terms (遵守合同条款)。 5. adjust - 意为“调整”或“调节”,常见于描述改变事物以达到最佳状态的情况,如...

    CSharp 3.0 With the .NET Framework 3.5 Unleashed(english)

    - **The Common Type System (CTS)**: The CTS defines the types and structures that all .NET languages must adhere to, ensuring interoperability between different languages. - **The Common Language ...

    职称英语考试高频词汇总结.doc

    例如:We must adhere to the deadlines set by the project manager. 27. adjacent:毗邻的。例如:The park is adjacent to the school, providing easy access for students. 28. adjust...to:调整以适应。例如...

    2010四级必备单词精选

    16. **adhere to**:坚持,遵循,例如:adhere to my opinion(坚持我的观点)。 17. **adjust to**:调节,适应,例如:adjust to the new life(适应新生活)。 18. **take advantage of**:欺骗,利用,例如:...

    Skill Up: A Software Developer's Guide to Life and Career

    This style of teaching is conducive to learning how to build real-world products that adhere to industry best practices. Additionally, Jordan has published multiple books on programming and computer...

    新东方六级高频词组.doc

    3. adhere to - 坚持遵循,例如:We must adhere to the schedule. 4. ahead of - 在...之前,例如:She finished the project ahead of time. B部分: 1. bear upon - 对...施加影响,例如:The news will bear ...

    职称英语考试高频词汇总结完整版.doc

    例如:We should adhere to the principles of fairness and honesty. 26. adjacent:毗邻的,临近的。如:Our office is adjacent to the library. 27. adjust...to:调节,适应。例如:She quickly adjusted ...

    英语六级高频基础词汇500个

    例如:Adhere to your own principle. (坚持自己的原则) 10. adverse(不利的,有害的):形容词,常用来描述对人或事产生负面影响的情况。例如:Adverse circumstances can test a person’s wisdom and courage...

    C++_CLI标准.pdf

    - **Conformance**: Chapter 3 details conformance, ensuring that implementations adhere to the standards set out by the specification. - **Normative References**: Chapter 4 lists normative references, ...

    成人本科学士学位英语考试词汇重点(打印版).pdf

    例如:We should adhere to the rules.(我们应该遵守规则。) 27. adjacent:毗邻的、临近的。例如:The two cities are adjacent.(两个城市毗邻。) 28. adjust:调节、适应。例如:I need to adjust the ...

    十年考研英语真题短语集锦.doc

    26. `adhere to` 坚持,如:We need to adhere to our principles. 27. `adjacent` 临近的,如:The park is adjacent to the school. 28. `adjust...to` 适应,如:It takes time to adjust to a new job. 29. `...

    adhere:基于模式的数据验证器

    此存储库已废弃 坚持 坚持是一个简单的基于模式的数据验证器,并努力实现合规性。 然而,与 JSONSchema 规范不同的是,坚持在类型定义的关键字强制方面非常自以为是。 坚持允许根据声明的模式直接验证原始数据类型...

    考研英语固定搭配(阅读理解必备)

    例句:We must adhere to the principles of fairness and justice. 24. adjacent:毗邻的,临近的。 例句:The library is adjacent to the classroom building. 25. adjust…(to):调节,适应。 例句:He's ...

    Material Design implementation with AngularJS(Apress,2016)

    Take advantage of Angular Material, a UI component framework that works out of the box to design web pages that adapt to various screen sizes and adhere to Material Design specifications. This book ...

    完形填空词组及固定搭配常考汇总

    14. `adhere to`: 坚持,遵守 15. `after all`: 毕竟 16. `agree on`: 对……达成一致 17. `agree to`: 同意 18. `agree with sb.`: 同意某人的观点 19. `along with`: 和……一起 20. `alternate (with)`: 交替 21....

Global site tag (gtag.js) - Google Analytics