Java 中实用程序类的命名约定
在用Java编写实用程序类时,有哪些好的准则需要遵循?
包装应该“util”还是“utils”?是 ClassUtil 还是 ClassUtils?类何时是“助手”或“实用工具”?实用程序还是实用程序?还是使用它们的混合物?
标准 Java 库同时使用 Utils 和 Utilities:
- javax.swing.Utilities
- javax.print.attribute.AttributeSetUtilities
- javax.swing.plaf.basic.BasicGraphicsUtils
Apache使用各种Util和Utils,尽管主要是Utils:
- org.apache.commons.modeler.util.DomUtil
- org.apache.commons.modeler.util.IntrospectionUtils
- org.apache.commons.io.FileSystemUtils
- org.apache.lucene.wordnet.AnalyzerUtil
- org.apache.lucene.util.ArrayUtil
- org.apache.lucene.xmlparser.DOMUtils
Spring使用了很多Helper和Utils类:
- org.springframework.web.util.UrlPathHelper
- org.springframework.core.ReflectiveVisitorHelper
- org.springframework.core.NestedExceptionUtils
- org.springframework.util.NumberUtils
那么,如何命名效用类呢?