[swift-evolution] [Proposal draff] abstract classes and methods

Matthew Johnson matthew at anandabits.com
Thu Jan 7 13:01:29 CST 2016


> On Jan 7, 2016, at 12:57 PM, Gwendal Roué <gwendal.roue at gmail.com> wrote:
> 
> 
>> Le 7 janv. 2016 à 19:44, Matthew Johnson via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> a écrit :
>> 
>>> 
>>> On Jan 7, 2016, at 12:42 PM, David James via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> Not sure the language direction should encourage inheritance based structures, which abstract classes and methods do. That’s not to say that inheritance is dead, but that a modern language should encourage and support compositional patterns rather than inheritance based patterns. 
>> 
>> +1 to these comments.  This proposal notes that protocols would provide very similar behavior if they were allowed to have stored properties.  That has already been discussed a little bit.  I think it would be best to decide whether that will happen or not before introducing abstract classes and methods.
> 
> I agree that the support for stored properties in protocols should definitely help avoiding the need for an abstract classes in many cases.
> 
> The problem, though, is that abstract classes still have something that protocol do not, and this is the encapsulation of implementation details. Protocols, on the other side, are open in the wide, expose all their inner guts. The problem with convenience protocols that expose too much implementation details is that they make refactoring very difficult, if possible at all. Abstract classes don’t have this issue.

That doesn’t have to be the case.  In fact, if an enhancement came along that allowed protocols to have stored properties I think there will be a request to allow access control on those properties.  If they aren’t required to have initial values some way to initialize them would also be necessary.  This would allow pretty strong encapsulation.

It is also possible that stored properties in protocols won’t be adopted or would be adopted without allowing for encapsulation.  If that is the path that we follow then you make good points.  I am just suggesting that we might want to wait and see before considering abstract classes.  It might turn out that they really aren’t necessary.

> 
> So I think protocols still have a long, long, way before they can match abstract classes.
> 
> Gwendal
> 

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


More information about the swift-evolution mailing list