Very Objective
Very Objective

Reputation: 626

What does "multiple base classes" mean?

The "Objective-C for Java Programmers, Part 1" intro by David Chisnall states that

Because you can have multiple base classes, Objective-C introduces the id type to represent a pointer to some kind of object. You can implicitly cast between any object type and id.

To the best of my understanding, Objective-C is single-inheritance (just like Java, but unlike C++).

So what does "multiple base classes" mean (in this context)?

Upvotes: 2

Views: 182

Answers (1)

bbum
bbum

Reputation: 162722

It means that you can define your own root or "base" class.

@interface MyRootClass
@end

Note that it does not inherit from NSObject.

In practice, this is never done because said class can't really be used inter-operably with the rest of the system APIs because they all expect NSObject inherited behavior.

That isn't really the motivation behind the id type, though. The id type means, quite literally, this object reference can be an instance of any class.

That there may be multiple base classes is entirely orthogonal.

No, implementing the NSObject @protocol isn't really good enough.

Upvotes: 3

Related Questions