将类名放在成员例程中是多余的吗?

发布于 2024-08-13 07:34:09 字数 339 浏览 2 评论 0原文

假设您有一个类 Block...

class Block {

并且它有一个功能可以让您在屏幕上显示该块。你会称之为...

ShowBlock( ... )

或者只是

Show( ... )

这一直让我烦恼,我想听听其他人的想法。一方面,ShowBlock 无论何时使用都是完全显而易见的。但是,由于它将从块中调用,因此可能没有必要,例如......

m_SomeBlock.ShowBlock( ... );

Say you have a class Block...

class Block {

and it has a function that allows you to show the block on screen. Would you call it...

ShowBlock( ... )

or just

Show( ... )

This has been irking me, and I'd like to hear others thoughts. On one hand, ShowBlock is completely obvious whenever its used. However, since it will be called from a Block, it may be unnecessary like...

m_SomeBlock.ShowBlock( ... );

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

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

发布评论

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

评论(2

空城之時有危險 2024-08-20 07:34:09

这是。该方法是类的成员,因此变为:

Block::Show()

该函数变为 Show 是 Block 的成员。如果方法名称是 ShowBlock,则它将被读取为 ShowBlock 是 Block 的成员。

It is. The method is a member of the class so it becomes:

Block::Show()

The function becomes Show is a member of Block. If the method name was ShowBlock the it would be read as ShowBlock is a member of Block.

溇涏 2024-08-20 07:34:09

我认为这不仅仅是多余的,除非您有严格的命名约定,否则它可能会令人困惑,例如:

Block_Show();
Block_Draw();
Block_Whatever();

并且示例中的实例化名称中已经包含“Block”,因此当另一个程序员需要更多内容时,这应该会帮助他/她有关方法或类的信息。

I think it is more than redundant, it can be confusing unless you have a strict naming convention, for instance:

Block_Show();
Block_Draw();
Block_Whatever();

And your instantiation in the example already has "Block" in the name, so that should help another programmer when he/she needs more information on the method or class.

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