将类组织到命名空间中

发布于 2024-07-06 03:21:49 字数 89 浏览 7 评论 0原文

将类组织到命名空间中是否有一些原则?

例如,如果命名空间 N 中的类依赖于 NX 中的类,可以吗? 如果 NX 中的类依赖于 N 中的类?

Are there some principles of organizing classes into namespaces?

For example is it OK if classes from namespace N depends on classes from N.X?
And if classes from N.X depends on classes from N?

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

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

发布评论

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

评论(2

心在旅行 2024-07-13 03:21:49

一般来说,如果您的包是“N.UI”和“N.Util”,那么这对于您的示例来说应该没问题。 我见过命名空间以两种常见方式使用:

1)系统的所有层都有一个命名空间(即数据库、网络、商业等)
2) 每个组件都有一个命名空间(即“客户”、“发票”)和下面的分层命名空间。

无论哪种方式,子命名空间都将是更大命名空间内相互关联的包,因此 UI 代码依赖于域对象是完全可以的。

然而,虽然 NX 类依赖于 N 中的类很好,但我认为 N 中的类依赖于 NX 中的类没有多大意义——听起来在这种情况下你可以使用一些重组。

In general, that should be fine for your example, if your packages were "N.UI" and "N.Util". I've seen namespaces used in two general fashions:

1) All tiers of a system have a namespace (i.e. database, web, biz, etc.)
2) Each component has a namespace (i.e. Customer, Invoice) and tiered namespaced underneath

Either way, the sub namespaces would be inter-related packages within a larger namespace, so it would be perfectly fine for you UI code to depend on your domain objects.

However, while it would be fine for N.X classes to depend on classes from N, I don't think it would make much sense for classes from N to depend on classes from N.X - it sounds like you could use some reorganization in that case.

枯寂 2024-07-13 03:21:49

NX 中的类可以依赖 N 中的类。 但是 N 中的类不应依赖于 NX 中的类; 那是糟糕的设计。

一些命名空间指南:

Classes in N.X can rely on classes in N. But classes in N shouldn't rely on classes in N.X; that's bad design.

Some namespace guidelines:

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