[swift-evolution] [swift-evolution-announce] [Review] SE-0026 Abstract classes and methods

Alex Hoppen alex at ateamer.de
Sat Feb 27 01:12:52 CST 2016

+1 for the proposal.
As I said in the original discussion abstract classes allow you to override methods of existing classes, which protocols cannot do (and by definition will never be able to do). I think this is a major advantage that cannot be neglected.
To name an example: Without abstract classes there is no way to create NSOperations that perform preliminary setup (like checking dependencies, notifying observers, …) and call through to the actual operation’s implementation in between (I’m referring to the sample code of the Advanced NSOperation’s talk at last year’s WWDC, where Operation would have greatly benefitted from making the execute method abstract). 
Sure, there are ways to work around this issue. As suggested several times you may define a delegate that does the actual operation’s work, which I don’t like because it a) defeats the concept of the operation performing the actual work, b) requires you to always think about two types (the operation and the delegate) when needing to override other methods of the actual operation and c) it does not make sense to create a raw (NS)Operation on its own. Alternatively there is the current way of doing it by creating a class that has a fatalError implementation but I guess nobody will argue that this is the right way to go. Or you may say that NSOperation should have been designed in another way so that it leverages protocols from the ground up. But it isn’t designed that way and there are huge amounts of code that were written before Swift introduced protocols and protocol extensions. I think from a point of interoperability it would simply be wrong to assume that this code does not exist.
Swift is a multi-paradigm programming language and POP isn’t the silver bullet that solves all our problems. IMO there are several use cases where abstract classes are the cleaner solution than a mix of protocols, extensions and classes (which have there use cases as well). It may, however, be beneficial to delay the introduction of abstract classes to Swift 4, so that people get more used to POP and see the benefits it brings with it and will not fall back to old (and maybe bad) patterns using abstract classes where POP would be the right way to go.

– Alex

> On 26 Feb 2016, at 19:11, Joe Groff <jgroff at apple.com> wrote:
> Hello Swift community,
> The review of “Abstract classes and methods” begins now and runs through March 4, 2016. The proposal is available here:
> https://github.com/apple/swift-evolution/blob/master/proposals/0026-abstract-classes-and-methods.md <https://github.com/apple/swift-evolution/blob/master/proposals/0026-abstract-classes-and-methods.md>
> Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:
> Proposal link:
> https://github.com/apple/swift-evolution/blob/master/proposals/0026-abstract-classes-and-methods.md <https://github.com/apple/swift-evolution/blob/master/proposals/0026-abstract-classes-and-methods.md>
> Reply text
> Other replies
> What goes into a review?
> The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
> 	• What is your evaluation of the proposal?
> 	• Is the problem being addressed significant enough to warrant a change to Swift?
> 	• Does this proposal fit well with the feel and direction of Swift?
> 	• If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
> 	• How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
> More information about the Swift evolution process is available at:
> https://github.com/apple/swift-evolution/blob/master/process.md <https://github.com/apple/swift-evolution/blob/master/process.md>
> Thank you,
> -Joe
> Review Manager
> _______________________________________________
> swift-evolution-announce mailing list
> swift-evolution-announce at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution-announce

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

More information about the swift-evolution mailing list