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

Gwendal Roué gwendal.roue at gmail.com
Thu Jan 7 13:18:46 CST 2016


> Le 7 janv. 2016 à 20:01, Matthew Johnson <matthew at anandabits.com> a écrit :
> 
>> 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.

You clearly address the hiding of implementation details from the code that uses types adopting such a protocol. But I’m not sure those implementation details can be hidden from the adopting types themselves?

> 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.


And we’ll continue fatalError("subclass must override") :-)

Gwendal

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


More information about the swift-evolution mailing list