|
|
|
|
|
by dunham
2854 days ago
|
|
A "protocol" in swift is equivalent to an "interface" in Java. "protocol" seems to be the older name (per one of the guys that wrote Java): > I'm pretty sure that Java's'interface' is a direct rip-off of Obj-C's 'protocol' -- https://cs.gmu.edu/~sean/stuff/java-objc.html
So "protocol oriented programming" is just advocating the use of swift's equivalent of java interfaces. (It'd be "interface oriented programming" in Java.)Edit: apologies if you know all this already, it just sounded like you were asking "what makes this protocol stuff better than interfaces". |
|
Quite likelym as another Guy (Steele) responsible for Java was also a big name in the Lisp world, including chairing the committee that wrote ANSI standard for Common Lisp. In the Lisp world, protocols were a known concept. In CL nomenclature, a protocol is a set of generic functions and types used by those functions. Which is kind of like a Java interfaces, except with multiple dispach based on any of the arguments instead of the typical single dispatch of Java and friends.
For example from TFA, a CL protocol would be a #'draw generic function and a 'drawable and 'renderer abstract types. The particular #'draw methods could be specialized on either argument (or both), and we could also imagine another protocol consisting of (the same) renderer type and some geometry-related generic functions.
Point being, protocols are both an old and very useful concept, and like usual, C++/Java-like languages only allow expressing a small subset of it.