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

Sean Heber sean at fifthace.com
Fri Feb 26 13:21:11 CST 2016


> Proposal link:
> 
> https://github.com/apple/swift-evolution/blob/master/proposals/0026-abstract-classes-and-methods.md
> 	• What is your evaluation of the proposal?

I am mixed on this. I’ve mentioned wanting this myself on this list and have run into situations where I *really* wished I had it at the time (instead of having to do fatalError()), but ultimately I’ve almost always gone back to redesign those things to get rid of the abstract base class pattern and improved the design in the process. Perhaps this is an anti-pattern and Swift should not encourage it. I’m not sure.


> 	• Is the problem being addressed significant enough to warrant a change to Swift?

I’m not so sure. I feel like by not having it, Swift has often pushed me toward better design (at the cost of some of my hair).


> 	• Does this proposal fit well with the feel and direction of Swift?

Again, I’m not sure about this. I don’t think the potential of protocols have been fully explored yet and this feels like just adding an old feature from old languages because that’s the way we’re used to doing it. I feel like you could get the same effect by having a way to apply a single protocol to a class “abstractly” and have that *result in* an abstract class. This would more clearly separate the parts that are meant for subclasses to fill in vs. not. For example, to use the class from the proposal:

protocol RESTClientSubclass {
  var url : String { get }
}

class RESTClient: @abstract(RESTClientSubclass) {}

class MyRestServiceClient : RESTClient {
  var url : String { return "http://www.foo.com/client” }
}

“override” wouldn’t be necessary here because you’re not actually overriding anything and the methods/properties the subclass needs to implement are clearly grouped together in the RESTClientSubclass protocol. (In fact it might even be an error for RESTClient to implement *any* method itself in an abstract protocol conformance).


> 	• If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

Yes and it doesn’t feel any different - which is what bothers me, perhaps. :)


> 	• How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Skimmed the discussions as they happened a bit, read the proposal, but did not spend significant time on it.

l8r
Sean



More information about the swift-evolution mailing list