[swift-evolution] [Pitch] Requiring proactive overrides for default protocol implementations.

Erica Sadun erica at ericasadun.com
Thu Apr 28 19:51:58 CDT 2016


> On Apr 28, 2016, at 6:44 PM, Andrew Bennett <cacoyi at gmail.com> wrote:
> 
> Hey, what annotations would I have in this case:
> 
> Module 1:
> Type AType { func foo() { ... } }
> Module 2:
> import Module1
> protocol A { func foo() {...default...} }
> extension AType: A {}
> 

No annotations. AType's implementation of foo is unrelated to its conformance, which is satisfied by its existing foo method.


> Also, for your alternatives section:
> 
> protocol A { func foo() {...default...} }
> Type AType: A {
>     func A.foo() {...replacement...}
> }
> 
> I actually prefer this alternative, I think it fixes many issues.

Protocol default implementations do not yet exist.  

In this second, you're suggesting instead of doing "override required", you use a naming approach that ties the implementation the specific protocol. I'm not really won over by this approach:

* It does clarify why the method is included
* It does not clarify that the method overrides an existing implementation.
* It could be more easily confused when members are required by multiple protocols.

-- E

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160428/4e8d8812/attachment.html>


More information about the swift-evolution mailing list