杂项功能的静态类的理想类名

发布于 2024-08-09 23:37:56 字数 140 浏览 5 评论 0原文

什么是我的静态类的理想类名,它有一些静态方法来处理常规/通用功能,例如备份、保存最近的项目等。(事实上,杂项项目)在 C# 中。我希望 Manager 作为类名的后缀(例如:SaleManager(处理销售相关功能),ContatManager(处理联系人相关功能)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

叹倦 2024-08-16 23:37:56

重构MeManager。

RefactorMeManager.

岁月打碎记忆 2024-08-16 23:37:56

以下是执行这些类型操作的一些 .NET Framework 类:

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

如您所见,例程是按主题分组为类,并且没有一个类附加“Helper”或“Utilities”。以下是我制作的一些类,它们执行其中一些类型的操作:

  • SymbolicMath (与 Math 类类似,但用于处理符号数学表达式)
  • BigIntegerMath (使用 System.Numerics.BigInteger 类型的大整数算术库 - 素性证明、因式分解和其他一些事情)

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)
心是晴朗的。 2024-08-16 23:37:56

事实证明,“效用”是有争议的,而“数学”则没有。因此,这个名称似乎应该表明静态类中方法的整体功能。

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.

酒解孤独 2024-08-16 23:37:56

如果您有一个包含大量静态方法的 Utility(或 UtilityManager)类,那么这确实是一种反模式,应该立即重构。

然而,有些东西就是这样的——实用程序,人们不应该把它们放在一个单独的实用程序类中(我个人最喜欢的)。是的,这为各种丑陋的场景打开了大门,一个人必须掌控一切,否则任何事情都会最终在那里,是的,需要将方法“提升”到他们自己的类(通常是 XXXHelper)如果需要的话,但是,尽管如此,我发现 Utilities 类是一个有用的构造,而不是其本身的反模式。模式毕竟是一种建议,它们不是一种宗教:)

Manager 作为此类类的后缀会令人困惑,因为该类实际上不管理任何东西。

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.

花开浅夏 2024-08-16 23:37:56

内部静态类 Utils 万岁。

Long live internal static class Utils.

一个人的夜不怕黑 2024-08-16 23:37:56

我总的感觉是不应该上这么一般的课。特别是电子邮件,很可能扩展到不仅仅是 SendEmail() 方法,而且坦率地说,new Email({to, subject, body}).Send() 更具有面向对象的意义。

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.

你与昨日 2024-08-16 23:37:56

实用程序管理器..?

UtilityManager..?

眼泪也成诗 2024-08-16 23:37:56

工具
实用工具
扩展(如果您只在其中放置扩展方法 (C#))

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

站稳脚跟 2024-08-16 23:37:56

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

梦行七里 2024-08-16 23:37:56

即使对于静态类(顺便说一句:我更喜欢 XxxHelper 后缀),我也会坚持“关注点分离范例”并且不会在一个类中混合不同的实用程序。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文