第一个没有代码的非抽象虚拟方法的特殊名称?
这个问题来自另一个类似的问题。有时我必须处理这个案子。
你知道在面向对象编程中是否存在一个特殊的名称,对于已声明为虚拟
的初始方法,即有意不是抽象
,但是,什么也不做,或者根本没有任何代码,但是,也许被称为?
这个示例是伪代码,但是适用于任何 OO 编程语言:
public class MyBaseClass
{
public abstract virtual void OverrideMe();
public virtual void DoSomething() { cout << "Hello Mars\n" }
public virtual void MayDoSomething() { /* Nothing, yet */ }
}
public class MyDerivedClass : MyBaseClass
{
public override void OverrideMe() { cout << "Hello Neptune\n" }
public override void DoSomething() { cout << "Hello Jupiter\n" }
public override void MayDoSomething() { cout << "Hello Venus\n" }
}
方法 MyBaseClass::MayDoSomething()
就是这种情况。
干杯。
This questions comes from another similar question. Sometimes I have to deal with this case.
Do you know if exist an special name in Object Oriented Programming, for a initial method that has been declared virtual
, that is intentionally not abstract
, but, does nothing, or does not have any code at all, but, maybe called ?
This example is pseudocode, but, applies to any O.O. programming language:
public class MyBaseClass
{
public abstract virtual void OverrideMe();
public virtual void DoSomething() { cout << "Hello Mars\n" }
public virtual void MayDoSomething() { /* Nothing, yet */ }
}
public class MyDerivedClass : MyBaseClass
{
public override void OverrideMe() { cout << "Hello Neptune\n" }
public override void DoSomething() { cout << "Hello Jupiter\n" }
public override void MayDoSomething() { cout << "Hello Venus\n" }
}
The method MyBaseClass::MayDoSomething()
its the case.
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我一般不知道这个名称,但我听说过使用这种方法的技术的各种名称。我想说这取决于具体用途。
唯一的通用名称我能想到的是一个 NOP 方法!
I don't know a name for this in general, but I've heard various names for techniques that use this kind of method. I would say it depends on the specific use.
The only general name I can think of is a NOP method!