On Apr 1, 2010, at 11:25 AM, Andreas Grosam wrote: > Still, I see an advantage when using protocols. The argument of changing > interfaces does not count IMO, since Categories are prone to changes as well. > If sometimes the category get removed or the methods get changed, my code > will not run anymore ;) > I don't think this will happen, though.
But protocols have a worse versioning problem than classes or categories. It's not just removed or changed methods. You also cannot add methods to a protocol, but you can add methods to a class. That's why the new thread perform methods were added to class NSObject but were not added to protocol NSObject. If you add a method to a class, all subclasses inherit that new implementation. Any old subclasses still honor the new interface without being recompiled. If you add a method to a protocol, the classes that conform to the protocol do not get a new method implementation. Old classes therefore do not honor the new interface, even though -conformsToProtocol: returns YES. The upshot is that you can add new methods to a class (with care toward other compatibility issues, of course), but that you can't add a new required method to a protocol unless you also control every class that conforms to that protocol. -- Greg Parker gpar...@apple.com Runtime Wrangler _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com