Objective-C的抽象类 [英] Abstract class for Objective-C

查看:115
本文介绍了Objective-C的抽象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在目标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接口。如果您要寻找Java中的纯虚拟 C ++类或接口的等效项,这就是您想要的。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆