tags:

views:

29

answers:

2

Can anyone please guide me on how to avoid overriding of superclass methods in subclass in Objective-C, like the "final" concept in Java.

+2  A: 

You can't. You can't even be sure that a leaf class's methods are the ones you supplied, because we can use the Objective-C runtime library to replace method implementations in a running application. That's a deliberate feature of the runtime library's design.

Graham Lee
ok, then how to protect my super class properties,that can't change through out the object existence. and how developer handles these situation while writing the frameworks or wrappers.
chethan
@chethan you don't, or you document the requirement and hope developers follow it. You can do things like hide properties from KVC or obfuscate their use, but you can't stop people getting at them.
Graham Lee
A: 

Well I'm not sure about a "final" equivalent in objective c but if there are methods in a super class that you don't want called just don't write that particular method in your sub class

Plus I think a method written with "+" prefix as opposed to "-" is a class method and not an instance method so that method should always be the same.

dubbeat