可能重复:
Creating an abstract class in Objective C在Objective C中模拟抽象类和抽象方法?
在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')?
谢谢!
请参阅此主题[http://stackoverflow.com/questions/1034373/creating-an-abstract-class-in-objective-c](http://stackoverflow.com/questions/1034373/creating-an- abstract-class-in-objective-c) –