【发布时间】:2012-06-28 15:36:57
【问题描述】:
在 Java 中,我喜欢使用抽象类来确保一堆类具有相同的基本行为,例如:
public abstract class A
{
// this method is seen from outside and will be called by the user
final public void doSomething()
{
// ... here do some logic which is obligatory, e.g. clean up something so that
// the inheriting classes did not have to bother with it
reallyDoIt();
}
// here the actual work is done
protected abstract void reallyDoIt();
}
现在如果类 B 继承自类 A,它只需要实现 reallyDoIt()。
如何在 Objective C 中做到这一点?有可能吗?在Objective C中可行吗?我的意思是整个范式在 Objective C 中似乎是不同的,例如据我了解,没有办法禁止覆盖方法(例如在 Java 中使用“final”)?
谢谢!
【问题讨论】:
标签: objective-c class methods virtual abstract