Objective-C 的抽象类 [英] Abstract class for Objective-C
问题描述
可能的重复:
在Objective C中创建抽象类
我想在 Objective-C 项目中创建抽象类.
I'd like to make abstract class in Objective-C project.
但是,我找不到诸如抽象"(在 Java 中)、虚拟"(在 C++ 中)之类的想法.
But, I can't find ideas suchlike 'abstract'(in java), 'virtual'(in c++).
Objective-C 没有抽象的概念吗?谢谢.
Doesn't Objective-C have an abstract idea? Thank you.
推荐答案
正式来说,没有.抽象类是通过在基类中删除方法然后记录子类必须实现这些方法来实现的.作者有责任编写与类契约匹配的类,而不是编译器检查丢失的方法.
Formally, no. Abstract classes are implemented by stubbing out methods in the base class and then documenting that a subclass must implement those methods. The onus is on the author to write classes that match the class contract rather than on the compiler to check for missing methods.
Objective-C 具有协议,类似于 Java 接口.如果您正在寻找与纯虚拟 C++ 类或Java 中的接口 等效的东西,这就是您想要的.
Objective-C has protocols, which are like Java interfaces. If you're looking for the equivalent to a pure virtual C++ class or an interface in Java, this is what you want.
这篇关于Objective-C 的抽象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!