[swift-evolution] [Proposal] Protected Access Level

Charles Srstka cocoadev at charlessoft.com
Mon May 30 04:22:24 CDT 2016


> On May 30, 2016, at 3:42 AM, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> I can't reply directly to all the points in this thread, but I will just say that there are ways of emulating protected in the language as it exists today:
>> 
>> If the goal is to have functions that can be overridden by subclasses without being called by external classes, you can create a parameter of a public type with a private initializer and use it in all "protected" member functions. No external code will be able to call such functions because they cannot create an argument of the correct type.
> As others stated before:
> I agree it's a cool little hack, but a hack none the less — and imho it isn't useful in real life.
> The focus should be documenting intend ("this method should be used in a certain way"). Creating clever countermeasures to stop users of a library to enforce limitations is imho the wrong way.

Couldn’t you use the same reasoning to claim there shouldn’t be access control at all? Just add documention on methods you want to mark private telling users of the library not to call them!

Charles

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


More information about the swift-evolution mailing list