Objective-C 中的多重继承 [英] Multiple inheritance in Objective-C

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

问题描述

可能的重复:
Objective-C 多重继承

我想在Objective-C中实现多重继承即我有一个Sub"类,它需要是Super"类和 UITableViewController 的子类

I want to implement multiple inheritance in Objective-C i.e. I have a class "Sub" which needs to be a sublass of class "Super" as well as UITableViewController

我怎样才能在 Obj-C 中达到同样的效果?

How can I acheive the same in Obj-C?

推荐答案

Objective-C 不支持多重继承.您可以使用协议、组合和消息转发来实现相同的结果.

Objective-C doesn't support multiple inheritance. You could use a protocol, composition and message forwarding to achieve the same result.

协议定义了一组对象必须实现的方法(也可以有可选方法).组合基本上是一种包含对另一个对象的引用并在需要其功能时调用该对象的技术.消息转发是一种允许对象将消息传递给其他对象的机制,例如,通过组合包含的对象.

A protocol defines a set of methods that an object must implement (it's possible to have optional methods too). Composition is basically the technique of include a reference to another object and calling that object when it's functionality is required. Message forwarding is a mechanism that allows objects to pass messages onto other objects, for example, an object that is included via composition.

苹果参考:

  • Protocols
  • Composition
  • Message Forwarding (and specifically Forwarding and Multiple Inheritance)

这篇关于Objective-C 中的多重继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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