objc-zen/objc-zen-book

Protocol Discussion incorrectly associates Protocols with Abstract Classes

quellish opened this issue · 0 comments

In the section on protocols, the book states:
"A great miss in the Objective-C world is the outcome of the latest decades about abstract interfaces. The term interface is typically used to refer to the .h file of a class but it has also another meaning well known to Java programmers which is basically used to describe to a set of methods not backed by a concrete implementation. "

This is not accurate. In objective-c class clusters provide abstract interfaces (and are, usually, abstract factories). NSString, NSNumber, etc. are all abstract interfaces implemented as class clusters. Several framework classes allow specific class clusters to be extended at runtime (NSURLProtocol, etc.).

https://developer.apple.com/library/ios/documentation/general/conceptual/devpedia-cocoacore/ClassCluster.html

In contrast, a protocol only defines a set of messages that an object can choose to implement.

https://developer.apple.com/library/ios/documentation/general/conceptual/devpedia-cocoacore/Protocol.html#//apple_ref/doc/uid/TP40008195-CH45-SW1