是的,确实如此。我在清洁代码一书的getter和setter中得出以下结论;如果你真的接受它就可以使用它。
Yes, It does. I have the following conclusion in getters and setters from the Clean Code book; you can use it if you really accept it.
- 非常邪恶:公共领域。
- 有点邪恶:吸气剂和二传手不需要它们。
- 好:只有在真正需要的地方才有吸气剂和制定者 - 使
类型暴露更大的行为恰好使用其状态
而不仅仅是将类型视为由其他类型操纵的
状态的存储库。
- Very evil: public fields.
- Somewhat evil: Getters and setters where they're not required.
-
Good: Getters and setters only where they're really required - make
the type expose "larger" behaviour which happens to use its state,
rather than just treating the type as a repository of state to be
manipulated by other types.