Tuesday, July 22, 2014

Override and overload in objective C

Objective C is message based and it has the full support on override. So if a method with the same signature is implemented in both the super class and derived class, calling the method will invoke the implementation in the derived class.

The object c does not support overload, so you cannot define or implement method with the same method name and parameter name but different return types or parameter types. The reason is objective C uses selector to distinguish different method, and select only use the information of method name and parameter name, and ignore the type information, for example, NSSelectorFromString method will only take method name and parameter name as input without parameter type information.

As a result, if a class has method only methods only different from parameter types, they will be regarded as the same method. This can particularly cause problem if the two methods are defined in super and derived class separately.

1 comment:

  1. Great Platform. Are you also searching for nursing essay writing help? we are the best solution for you. We are best known for offering the best nursing essay writing services

    ReplyDelete