Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple inheritance in Objective-C [duplicate]

Tags:

objective-c

Possible Duplicate:
Objective-C multiple inheritance

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

How can I acheive the same in Obj-C?

like image 211
hmthur Avatar asked Dec 21 '10 14:12

hmthur


People also ask

Is multiple inheritance possible in Objective C?

In keeping with its clean and simple design, Objective C does not support multiple inheritance, though features have been developed to replace some of the functionality provided by multiple inheritance (see run-time section below). The root of the Objective C class hierarchy is the Object class.

Why swift doesn t support multiple inheritance?

Swift doesn't allow us to declare a class with multiple base classes or superclasses, so there is no support for multiple inheritance of classes.

How do you inherit a class in Objective C?

When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.

Which inheritance is not supported in iOS?

In this blog, we are going to learn about the multiple inheritances in Swift and their implementation in your iOS project. Swift is an Object-oriented programming language but it does not support multiple inheritances. Learn more about inheritance from here.


1 Answers

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.

Apple Reference:

  • Protocols
  • Composition
  • Message Forwarding (and specifically Forwarding and Multiple Inheritance)
like image 200
Benedict Cohen Avatar answered Oct 12 '22 11:10

Benedict Cohen