[swift-evolution] Calling a Specific Implementation
Brent Royal-Gordon
brent at architechies.com
Fri Aug 19 05:06:23 CDT 2016
> On Aug 17, 2016, at 6:57 PM, John McCall via swift-evolution <swift-evolution at swift.org> wrote:
>
> Being able to bypass another class's overrides and jump to a specific superclass implementation on an arbitrary method call is badly encapsulation-breaking, and I can't think of any OO language with first-class support for it besides C++.
Perl 5 does, although of course its object system is a little bit...different.
What these languages have in common is multiple inheritance. Calling a specific superclass's implementation is necessary when you have more than one superclass. Swift doesn't have that problem with superclasses, but it *does* have it with protocol extension members.
My suggestion would be to allow you to call a particular protocol extension's implementation with:
super(ProtocolName).method()
`super(Foo)` would always use the appropriate member on `Foo`, which must be a protocol (not a class name), and must be conformed to by this type (not by a superclass). Unqualified `super` would only be valid in classes and would only permit calls to members of the superclass (including protocols it conforms to). That would permit access to default implementations without permitting encapsulation-breaking shenanigans, while leaving plain `super`'s meaning unambiguous.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list