实用程序库中应包含哪些内容

发布于 2024-07-10 17:35:17 字数 1449 浏览 14 评论 0原文

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

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

发布评论

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

评论(5

黯然 2024-07-17 17:35:17
  1. 我不会写一个名为“Common”或“Utilities”或“Misc”或......的库,你明白了。 相反,我有一个名为“Lib”的目录,并将每个功能区域放在该目录下的单独库中。 例如,我可能有用于 C++ 项目的 Lib/Trace、Lib/UI、Lib/Net、Lib/Web。 对于 C#,我有 Lib/Acme.Trace、Lib/Acme.Windows.Forms、Lib/Acme.Net 等(假设您的顶级命名空间/公司称为“Acme”)。
  2. 亚格尼。 不要编写您可能需要的代码。
  3. 在两个或多个项目中使用过的东西之前,不要将它们放入共享库中。
  1. I wouldn't write a library called 'Common' or 'Utilities' or 'Misc' or... You get the idea. Instead, I'd have a directory called 'Lib', and have each area of functionality in a separate library under that. For example, I might have Lib/Trace, Lib/UI, Lib/Net, Lib/Web for a C++ project. For C#, I'd have Lib/Acme.Trace, Lib/Acme.Windows.Forms, Lib/Acme.Net, etc. (assuming your top-level namespace/company is called 'Acme').
  2. YAGNI. Don't go writing code that you might need.
  3. Don't throw things into a shared library until you've used them in two or more projects.
淡淡绿茶香 2024-07-17 17:35:17

就我个人而言,我会将其中一些功能放入单独的库中,因为“实用性”是一个相当主观的术语,一个人认为有用的东西对另一个人来说就没那么有帮助。

如果在库中它被分解为描述性命名空间,那么我会说这更好(例如,调整图像大小将位于某种 .Drawing 命名空间中,或在 .Drawing.dll 中)。

Personally, I would put some of this functionality into separate libraries, as "utility" is a rather subjective term, what one person finds helpful is not so helpful to another.

If within the library it was broken up into descriptive namespaces, then I would say that's better (e.g. resize images would be in some sort of .Drawing namespace, or in a .Drawing.dll).

豆芽 2024-07-17 17:35:17

我的类库中有很多东西可以在项目之间共享:

  • IoC 容器和依赖注入框架
  • 完整的控制器/观察者框架,允许我将 UI 代码与后台逻辑代码分开
  • 用于执行 SQL 的合理的独立于数据库的类集,需要注意一些语法差异,主要是函数名称
  • 许多其他处理数据的帮助器类和实用方法
  • 一些标准化的内部存储类,如 Tuple<..> 等。
  • 一些自定义集合,如SetHeap,以及大量用于处理各种类型集合的实用方法。

当我需要更多东西时,会添加类库。

I have plenty of things in my class library which I share between projects:

  • IoC container and dependency injection framework
  • A full controller/observer framework, allows me to separate UI code from backlogic code
  • A reasonable database-independent set of classes for executing SQL, takes care of some of the syntax differences, mainly function names
  • Lots of other helper classes and utility methods for dealing with data
  • Some standardized internal storage classes, like Tuple<..> etc.
  • Some custom collections, like Set<T>, Heap<T>, as well as plenty of utility methods for dealing with various types of collections

The class library is added to when I need more stuff.

帅气尐潴 2024-07-17 17:35:17

我建议不要创建“实用程序”库,而是创建特定于域的(图形、身份验证、验证等)库,并且只在需要的地方包含它们。 当然关键在于具体到什么程度。 通常越具体越好。

无论如何,如果它没有域,那么您可能没有完全理解它,这意味着您应该首先重新评估您正在做的事情并试图完成的事情。

另外,请记住,对一两个项目有用的东西最终可能只对一两个项目有用。 添加过多的类只会导致后续的维护问题。

I'd suggest that instead of a "utility" library just make domain specific (graphics, authentication, validation, etc) libraries and only include them where they are needed. The key of course is decided how specific to be. More specificity is generally better.

Irregardless if it has no domain then you probably don't understand it fully meaning that you should re-evaluate what you are doing and trying to accomplish first.

Also, remember that what is useful in one or two projects may end up only being useful in one or two projects. Adding more classes than necessary only causes maintenance issues down the road.

山人契 2024-07-17 17:35:17

虽然我自己只是一个初出茅庐的开发人员,但我发现 RegEx 函数和 SQL 过滤器非常有用。 我还拥有 MSSQL 的合并复制功能,到目前为止这对我来说非常方便。

Though I am just a fledgling developer myself I have found RegEx functions and SQL filters to be quite useful. I also have Merge Replication functionality for MSSQL that has been quite handy for me so far.

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