[swift-users] Comparing POP to OOP
brent at architechies.com
Tue Feb 16 19:30:45 CST 2016
> We can override functionality provided from a protocol extension if we need specific functionality for a particular type.
No you can't. Protocol extension methods (that is, methods declared only in an extension, as opposed to default implementations, which are both declared in the protocol and defined in an extension) are statically dispatched, so calling them on the protocol witness will always use the extension's implementation, even if some concrete type conforming to the protocol has a different implementation with the same name and signature.
(I've worked on a proposal in the past that would require keywords to make this behavior clearer, but I've had trouble getting it through.)
In any case, I'm pretty sure that's what Daniel means when he says extension methods are exactly equivalent to global functions. Sure, they appear after a dot, have an implicit self parameter, and are scoped to a particular type, but there's nothing dynamic about their behavior—they're not overridable in any useful sense.
More information about the swift-users