可能重複:
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) –