Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

objective c categories and inheritance

If a method is defined in both a class and a category on that class, it is undefined which implementation will be called.

But how does this interact with inheritance? Specifically:

  • Given a superclass category method and a regular method in the subclass, is it guaranteed that the subclass implementation will win when called on a member of the subclass?
  • Given a superclass regular method and a subclass category method trying to override it, is it guaranteed that the subclass category implementation will win when called on a member of the subclass?
  • Given a superclass category method and a subclass category method, is it guaranteed that the subclass category method will win when called on a member of the subclass?
like image 553
William Jockusch Avatar asked Aug 10 '11 15:08

William Jockusch


People also ask

What is inheritance in Objective-C?

“ A key idea in all object-oriented programming, is inheritance that a new class can base itself on an existing class. It's another form of code reuse.

Does Objective-C support multiple inheritance?

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.

What are the objectives of inheritance?

Inheritance allows programmers to create classes that are built upon existing classes, to specify a new implementation while maintaining the same behaviors (realizing an interface), to reuse code and to independently extend original software via public classes and interfaces.


1 Answers

Lets just put it this way. Don't override methods using categories, period, ever, end of answer.

like image 100
Joshua Weinberg Avatar answered Sep 23 '22 00:09

Joshua Weinberg