[swift-users] Comparing POP to OOP

Dave Abrahams dabrahams at apple.com
Thu Feb 25 20:02:27 CST 2016

on Tue Feb 16 2016, Brent Royal-Gordon <swift-users-AT-swift.org> wrote:

>> 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.

The difference is that they can function as overrides of requirements,
which global functions cannot (insert obligatory caveat about operator
hack here).


More information about the swift-users mailing list