[swift-evolution] final + lazy + fileprivate modifiers

Brent Royal-Gordon brent at architechies.com
Sat Feb 18 05:05:01 CST 2017


> On Feb 17, 2017, at 2:15 PM, Joanna Carter via swift-evolution <swift-evolution at swift.org> wrote:
> 
> There are also times when I want to declare a base class that I am expecting users to derive from, especially an abstract class. I want a means of declaring that certain stuff can only be overridden by subclasses but, most definitely, not callable from any code outside of that hierarchy. For that, I express that intent by declaring such stuff as protected, thus preventing "unauthorised" use from outside the intended hierarchy.

Let's be clear here: Are you thinking of this exclusively as a feature for override points, or are you asking for a `protected` feature in general?

I think that a general `protected` feature is not very compatible with Swift's extension-based approach, but I could imagine a feature specifically for overriding. For example, a class like UIViewController might declare:

	open(override) internal func viewDidAppear(_ animated: Bool) { … }
	// Or maybe `open internal(call)`? That'd be more like `public internal(set)`…

And then public subclasses could override `viewDidAppear(_:)`, and those overrides could call `super.viewDidAppear(_:)`, but neither other methods in the subclass nor code outside the subclass could call it.

Would that fulfill your needs, or are you really looking for type-based access control?

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list