2

有些书说我们应该避免使用类似的名字'XXInfo''XXManager'(我忘记了书名),所以我试图找到这些名字的好人选,但我找不到一些好的替代品'UserInfo''ProxyManager'或者类似的东西。

任何人都可以就如何选择更具表现力的名称提供一些好的建议吗?我不是说英语的人

4

1 回答 1

3

Instead of UserInfo, you could just call your class "User", especially if it is in a module called "Data" or "InfoStore" or something like that. The word "Info" conveys a meaning that can be taken for granted.

It's harder to get rid of the "manager" word - I have tried this myself. (Sometimes one ends up with so many "Managers" that one almost needs a "ManagerManager" to sort them all out.) I think the important thing here, is to think "what does the class really do?"

Is it really a Wrapper, Helper, Retriever, Decider, Organiser, or Mapper?

If none of the above, then perhaps the "manager" class is simply too big, and should be split into separate functions that could be named accordingly. In some cases, you might be able to replace the word "manager" with "boss", especially if it is a manager of other managers objects.

(Answer, because I couldn't fit this long post into the comments)

于 2012-11-09T12:02:05.053 回答