Ideal class name for static class for misc functionalities [duplicate]

若如初见. 提交于 2019-12-08 10:44:44

问题


Whats is the ideal class name for my static class which has some static methods to handle General/Common functionalities iike taking backup,saving recent items etxc.. (Infact Misc items ) in C#. I would like to have Manager as suffix of the class name (ex: SaleManager(to handle sales related functionalities),ContatManager(to handle contact related functionality)


回答1:


RefactorMeManager.




回答2:


Here are some .NET Framework classes that perform these types of operations:

  • System.Environment
  • System.Math
  • System.IO.File
  • System.IO.Directory
  • System.IO.Path
  • System.Runtime.InteropServices.Marshal

As you can see, the routines are grouped by topic into classes, and none of the classes have "Helper" or "Utilities" appended. Here are some classes I've made that perform some of these types of things:

  • SymbolicMath (like the Math class, but for working with symbolic math expressions)
  • BigIntegerMath (library of large-integer arithmetic using System.Numerics.BigInteger type - primality proving, factoring, and some other things)



回答3:


It turns out that "Utility" is controversial, while "Math" is not. So it would seem that the name should suggest the overall functionality of the methods in the static class.




回答4:


Long live internal static class Utils.




回答5:


My general feeling is that one should not have such a general class. Email in particular is quite likely to expand to more than just a SendEmail() method and frankly new Email({to, subject, body}).Send() makes a lot more OO sense.




回答6:


If you have a Utility (or UtilityManager) class that has lots and lots of static methods, that is indeed an anti-pattern and should be refactored pronto.

However, there are the things that are just that - utilities, and one should not refrain from putting them in a separate Utilities class (my personal favourite). Yes, that opens the door for all sorts of ugly scenarios, and one has to hold the reins, or anything and everything will end up there, and yes, there is a need to "promote" methods to their own class (usually XXXHelper) if the need arises, but, nonetheless, I find the Utilities class a helpful construct, and not an anti-pattern by itself. Patterns are a recommendation after all, they are not a religion :)

Manager as a suffix for that kind of a class is confusing, because the class does not in fact manage anything.




回答7:


Tools
Utils
Extensions (if you put just extension methods in there (C#))




回答8:


UtilityManager..?




回答9:


There are very good reasons not to do that kind of thing. It is considered an anti-pattern.




回答10:


Even for static classes (btw: I prefer the XxxHelper suffix) I'd stick to the paradigm "Separation of Concerns" and would not mix different utilities in one class.



来源:https://stackoverflow.com/questions/1665660/ideal-class-name-for-static-class-for-misc-functionalities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!