- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
关闭。这个问题是opinion-based .它目前不接受答案。
想改进这个问题?更新问题,以便 editing this post 提供事实和引用来回答它.
3年前关闭。
Improve this question
我们公司保留了一个 MiscUtilities 类,该类仅由公共(public)静态方法组成,这些方法通常执行不相关的任务,例如将日期从 String 转换为 Calendar 并将 ArrayLists 写入文件。我们在其他类中引用它,发现它非常方便。但是,我看到过那种在 TheDailyWTF 上被 mock 的 Utilities 类。我只是想知道这类类(class)是否有任何实际的缺点,以及替代方案是什么。
最佳答案
我不会给出个人意见,而是引用 Java 社区的权威来源,以及来自 2 个非常有名的第三方库的示例。
Effective Java 2nd Edition, Item 4: Enforce noninstantiability with a private constructor 的引用:
Occasionally you'll want to write a class that is just a grouping of
static
methods andstatic
fields. Such classes have acquired a bad reputation because some people abuse them to avoid thinking in terms of objects, but they do have valid uses. They can be used to group related methods on primitive values or arrays, in the manner ofjava.lang.Math
orjava.util.Arrays
. They can also be used to groupstatic
methods, including factory methods, for objects that implements a particular interface, in the manner ofjava.util.Collections
. Lastly, they can be used to group methods on afinal
class, instead of extending the class.
Type
Utils
命名约定ArrayUtils
, StringUtils
, ObjectUtils
, BooleanUtils
等Type
s
命名约定Objects
, Strings
, Throwables
, Collections2
, Iterators
, Iterables
, Lists
, Maps
等static
类的特定部分实用方法Ints
, Floats
, Booleans
等static
实用程序类可以有效地将相关方法分组在:final
类(因为它们不可扩展)SomeType
的组实用程序方法至SomeType
Utils
或 SomeType
s
关于oop - 开设 Misc Utilities 类(class)是不是很糟糕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3531580/
我正在尝试第一次发布我的应用程序。如果我没记错的话,为了把admob 广告放到我的应用程序中,我应该有一个admob 帐户。 我的问题是我是否需要使用与打开 Play 商店开发者帐户相同的 gmail
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 提供事实和引用来回答它. 3年前关闭。 Improve this
我是一名优秀的程序员,十分优秀!