Khi viết các lớp tiện ích trong Java, một số hướng dẫn tốt cần tuân theo là gì?
Các gói có nên "dùng" hay "utils" không? Đó là ClassUtil hay ClassUtils? Khi nào một lớp là "Người trợ giúp" hay "Tiện ích"? Tiện ích hay Tiện ích? Hay bạn sử dụng hỗn hợp của chúng?
Thư viện Java tiêu chuẩn sử dụng cả Utils và Utilities:
- javax.swing.Utilities
- javax.print.attribute.AttributeSetUtilities
- javax.swing.plaf.basic.BasicGraphicsUtils
Apache sử dụng nhiều loại Util và Utils, mặc dù chủ yếu là 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 sử dụng rất nhiều lớp Helper và Utils:
- org.springframework.web.util.UrlPathHelper
- org.springframework.core.ReflectiveVisitorHelper
- org.springframework.core.NestedExceptionUtils
- org.springframework.util.NumberUtils
Vì vậy, làm thế nào để bạn đặt tên cho các lớp tiện ích của bạn?