[swift-users] Comparing POP to OOP

Dave Abrahams dabrahams at apple.com
Thu Feb 25 20:06:58 CST 2016


on Tue Feb 16 2016, Dmitri Gribenko <swift-users-AT-swift.org> wrote:

> On Tue, Feb 16, 2016 at 6:28 PM, Jon Hoffman via swift-users
> <swift-users at swift.org> wrote:
>> You are correct that if you are using the protocol type to interact with the
>> instance then the method defined in the protocol extension will be called
>> however if it is type casted to a concrete type which has a method that
>> overrides the method in the protocol extension then the method in the
>> concrete type would be called.
>
> The method in the concrete type does not override the method from the
> protocol extension, it merely shadows that method.

Technically true, but not really interesting because no instances of a
protocol extension exist.  Instances of the protocol (and generic
parameters constrained thereto) do exist, and the method in the concrete
type “overrides the lack of implementation” in the protocol itself,
which otherwise would have been satisfied by the extension.
Semantically, that is indistinguishable from the extension's
implementation being a default in the protocol itself, which is
overridden.

-- 
-Dave



More information about the swift-users mailing list