[swift-evolution] [Draft] Allow declaration of abstract functions and properties on classes

Vinicius Vendramini vinivendra at gmail.com
Fri Feb 26 12:45:17 CST 2016


It seems like having a protocol restricted to instances of ‘AccountAuthorizationController’ (as Brent suggested) would solve your problem, wouldn’t it?

You could just add all method declarations that are supposed to be abstract to that protocol instead, and then make sure your subclasses implement the protocol - which means the compiler forces them to implement the abstract methods.

> Currently I have in a private framework a class named `AccountAuthorizationController` with subclasses like `OAuthAccountAuthorizationController`, `OAuth2AccountAuthorizationController` and `WebFormAccountAuthorizationController` and so on.
> 
> In the root "abstract" class I have methods without implementation where I have to use `fatalError()` to ensure that they will never been called. I cannot prevent the framework user to instantiate the `AccountAuthorizationController`, however.
> 
> Look that this is only one example. I have other cases as well when I'd like to have abstract classes and abstract methods.
> 
> I know that structs and protocols are "elegant, simple and powerful" (as they seem to be all new frameworks and languages that pop up every day on the Internet) and the argumentsin favor of composition rather than inheritance. But I still would like to take advantage of the decades of available knowledge in object orientation in my projects.
> 
> +1 for abstract classes and abstract methods.
> 
> -Van
> 
> On Fri, Feb 26, 2016 at 12:46 PM, Evan Maloney via swift-evolution<swift-evolution at swift.org(mailto:swift-evolution at swift.org)>wrote:
> > >Well not exactly, if you want the same behaviors in subclasses of UIViewController and UITableViewController :
> > >- with protocols + extensions, you write in once and apply it to each of your subclasses
> > >- with abstract classes you have to write 2 abstract classes, one for direct UIViewController subclasses, one for UITableViewController subclasses
> > 
> > That's a problem with class hierarchies in general, not with abstract classes.
> > 
> > You can use the same argument to call for the removal of classes from Swift, which is why I think the fundamental question is, are classes intended to be first-class citizens in Swift?
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org(mailto:swift-evolution at swift.org)
> > https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160226/857dd2ed/attachment.html>


More information about the swift-evolution mailing list