博客 - BlogPost - BlogPostComment 与博客 - 帖子 - 评论

发布于 2024-08-25 11:58:24 字数 340 浏览 2 评论 0原文

不太知道如何制定标题,但从示例中应该很明显。

更具体地说,您使用什么规则来命名“依赖”类。例如,Blog 本身就是一个非常具有描述性的名称,但我该如何处理帖子呢? BlogPost 还是 Post?显然,名字清楚地表达了它是一个“从属”类,但这很快就会与 BlogPostCommentBlogPostCommentAttachment 等失控。Post 看起来像一个与 Blog 完全无关的实体,并且更容易被眼睛看到。

你们的规则/最佳实践是什么?

Don't really know how to formulate the title, but it should be pretty obvious from the example.

More specifically, what rules do you use for naming "dependent" classes. For example, Blog is a pretty descriptive name itself, but how do I deal with posts? BlogPost or Post? Clearly, first name clearly expresses that it's a "subordinate" class, but this can quickly get out of hand with BlogPostComment, BlogPostCommentAttachment, etc. Post, on the other hand, looks like an entity completely unrelated to Blog and is easier on the eye.

What are your rules/best practices?

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

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

发布评论

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

评论(3

呢古 2024-09-01 11:58:24

我个人最喜欢后者。一个好的命名空间名称不会消除 Post 的歧义吗?

I personally like the latter best. And wouldn't a good namespace-name disambiguate Post?

稀香 2024-09-01 11:58:24

在您提到的情况下,这个问题是如此众所周知,因此简洁并没有什么区别,而且实际上可以节省您的打字时间。其他类型的类之间的关系并不是那么一成不变。

使用“博客”、“帖子”和“评论”的另一个好处是,您可以将“帖子”和“评论”重复用于其他不一定与博客相关的内容,并且它们更适合放在那里(好吧,这只是一个重命名)。

我的规则就是“尽可能清晰”。我确实倾向于假设,在你闯入我的代码,或者我开始一个项目之前,我们已经阅读了一些有关问题空间的内容。

此外:我知道的大多数 Web 框架都让使用简洁的名称(例如 Blog、Post 等)作为模型名称变得更加容易。

In the case you mention, the problem is so well known as it makes no difference to be terse, and it actually saves you typing. Other types of relationships between classes aren't so cut-and-dry.

Another plus to using "Blog", "Post" and "Comment" is that you could reuse Post and Comment for other stuff not necessarily blog-related, and they'd fit better there (ok, it's just a rename anyway).

My rule would then be 'be as clear as you can'. I do tend to assume that, before you come barging in on my code, or I start a project guns ablaze, we have read a bit about the problem space.

Furthermore: most web frameworks I know make things much easier to use terse names like Blog, Post, etc. for model names.

醉南桥 2024-09-01 11:58:24

有趣的问题。我会根据情况使用其中之一。

例如,一个简单的 News 和 NewsItem 就可以了,因为它是一个基本模型,并且命名约定使这种情况下的关系变得清晰。

然而,对于具有更复杂的域模型和维护良好的命名空间(例如博客)的大型开发,我想说,命名类型博客、帖子、评论必须更简单、更简洁。

Interesting question. I would use either depending on the situation.

For example a simple News and NewsItem would be fine as it's a basic model and the naming convention makes the relation clear in this case.

However, for larger developments with more complex domain models and well maintained namespacing (for example a blog) I would say it's must less convoluted and cleaner to name the types Blog, Post, Comment.

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