将类名放在成员例程中是多余的吗?
假设您有一个类 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是。该方法是类的成员,因此变为:
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.
我认为这不仅仅是多余的,除非您有严格的命名约定,否则它可能会令人困惑,例如:
并且示例中的实例化名称中已经包含“Block”,因此当另一个程序员需要更多内容时,这应该会帮助他/她有关方法或类的信息。
I think it is more than redundant, it can be confusing unless you have a strict naming convention, for instance:
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.