C++ 中层次结构的命名

发布于 2024-11-14 00:32:35 字数 481 浏览 9 评论 0原文

我需要有关以下层次结构的建议,我想在 C++ 程序中表示。

有一个抽象类 uri 以及从它派生的类 urlurn。 我想要一个包含 uri 概念的源代码的目录。还有一个名称空间,应该称为 ..uri。 :)

所以,我来回答我的问题。 当命名空间已经被称为“uri”时,我该如何命名抽象类“uri”呢? C++ 中此问题通常采用什么命名约定? base、uri_base、basic_uri 或者你会如何命名它?

我的第二个问题是。在用户感到乏味之前,您可以多久嵌套一次名称空间?例如,我有 uri 部分,如 authorityquery 等。 创建一个新的命名空间(例如:parts)并将此类的源代码放在一个新的子目录中是否明智?或者这只是“过度设计”?

谢谢并致以

诚挚的问候

I need advice for the following hierarchical structure, I want to represent in a C++ program.

There is one abstract class uri and the classes url and urn which derive from it.
I would like to have one directory containing the source code of the uri concept. And a namespace which should be called .. uri. :)

So, I'm coming to my question.
When the namespace is already called "uri", how would I name the abstract class "uri" then?
What naming convention is usual for this problem in C++?
base, uri_base, basic_uri or how would you name it?

And my second question is. How often can you nest namespaces before users get tedious of it? For example, I've got uri parts like authority, query and so on..
Would it be wise to create a new namespace (for example: parts) and put the source code of this classes in a new subdirectory? Or does this just get "overdesigned"?

Thanks and regards

reeaal

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

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

发布评论

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

评论(3

笑着哭最痛 2024-11-21 00:32:35

命名空间不基于也不应该基于保存文件的实际目录。
它们的目的是将相关的类/结构/常量组合在一起并减少歧义。

将类命名为与其包含的命名空间相同的名称(例如 uri::uri)是没有问题的。应根据将要使用这些类的程序员来选择名称。

Namespaces are not based nor should they be based on the actual directories that hold the files.
Their purpose is to group related classes/structs/constants together and reduce ambiguities.

There is no problem with naming a class the same as its containing namespace (such as uri::uri). Names should be chosen with the programmer that will use the classes in mind.

转角预定愛 2024-11-21 00:32:35

当命名空间已经被称为“uri”时,我该如何命名抽象类“uri”呢?

如果需要,您可以简单地将其命名为“uri”,您可以拥有与封闭名称空间同名的标识符,没有问题。

When the namespace is already called "uri", how would I name the abstract class "uri" then?

You can simply name it "uri" if you want, you can have an identifier with the same name as the enclosing namespace with no problem.

ζ澈沫 2024-11-21 00:32:35

您滥用名称空间。它们的存在本质上是为了防止库之间的名称冲突 - 一般来说,每个库应该有一个命名空间。

You are misusing namespaces. They are there essentially to prevent name clashes between libraries - you should, in general, have ONE namespace per library.

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