公用事业类的最佳实践? [英] Best Practice for Utilities Class?

查看:57
本文介绍了公用事业类的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前有一个实用程序类,可以处理许多字符串格式,日期显示和类似功能,并且是共享/静态类.

We currently have a utilities class that handles a lot of string formatting, date displays, and similar functionality and it's a shared/static class.

这是正确"的处理方式还是我们应该在需要时实例化实用程序类?

Is this the "correct" way of doing things or should we be instantiating the utility class as and when we need it?

我们这里的主要目标是减少内存占用,但应用程序的性能也是一个考虑因素.

Our main goal here is to reduce memory footprint but performance of the application is also a consideration.

PS.我们正在使用.NET 2.0

PS. We're using .NET 2.0

推荐答案

如果类中根本没有任何状态,那么最好用它来制作对象.就对象依赖和线程安全而言,单例很麻烦.

If there is any state in the class at all, then it is best to make objects out of it. Singletons are a pain, with respect to object dependencies, and thread safety.

如果类中没有状态,那么是否将其设置为静态的选择不会对内存占用产生明显影响.

If there is no state in the class, then the choice about whether to make it a static or not will have no appreciable affect on memory footprint.

这篇关于公用事业类的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆