<div dir="ltr">That&#39;s the key point.<div><br></div><div>&quot;Protected&quot; would increase the expressivity of the language by declaring intent and exposing cleaner public APIs.</div><div><br></div><div>I don&#39;t think this idea should be dropped just because <span style="font-size:12.8px">conscious</span> hacks/decisions can workaround it, so big +1 for it.</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-03-30 5:51 GMT+01:00 Thorsten Seitz via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have no problems with &quot;protected&quot; members being made accessible in subclasses or extensions because this requires conscious decisions and actions to extend the API.<br>
Access levels are not there to protect against hacking, they are there to ensure that something can only be used through its given API. They are not there to restrict extending that API.<br>
<br>
Having said that I&#39;d love to have &quot;protected&quot;.<br>
<br>
-Thorsten<br>
<div class="HOEnZb"><div class="h5"><br>
&gt; Am 30.03.2016 um 03:28 schrieb Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br>
&gt;<br>
&gt;<br>
&gt;&gt;&gt; On Mar 29, 2016, at 6:18 PM, Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Mar 29, 2016, at 6:04 PM, Dietmar Planitzer via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Well that would be true if we assume that protected would work that way. Considering that this:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; private class A { … }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; public class B : A { … }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; is not allowed in Swift, I don’t see a good reason why an override of a protected method should be allowed to upgrade the access level to public. On the other hand this:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; public class A {<br>
&gt;&gt;&gt;  private func foo() {<br>
&gt;&gt;&gt;      print(&quot;A&quot;)<br>
&gt;&gt;&gt;  }<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; public class B : A {<br>
&gt;&gt;&gt;  public override func foo() {<br>
&gt;&gt;&gt;      print(“B”)<br>
&gt;&gt;&gt;  }<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; happens to actually work if both A and B are defined in the same file - which is rather unexpected. I would have expected that Swift would in general not allow overrides to upgrade the inherited access level. Eg exposing semantics which is embodied in a private or protected method should require a conscisous design decision and should require the designer to introduce a separate method name which is part of the public API. The public method can then call through to the private or protected method as needed.<br>
&gt;&gt;<br>
&gt;&gt; That would still be a toothless restriction, since a subclass could define a new method:<br>
&gt;&gt;<br>
&gt;&gt; public class B : A {<br>
&gt;&gt;  public func foo_() {<br>
&gt;&gt;      super.foo()<br>
&gt;&gt;  }<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; From an interface perspective, there&#39;s no difference between a subclass defining a new method or overriding a method that happens to be private to the base class.<br>
&gt;<br>
&gt; Extensions further dilute the enforceability of &quot;protected&quot;, since anyone would be able to use an extension to dump methods into a class&#39;s namespace and access its supposedly-protected bits.<br>
&gt;<br>
&gt; -Joe<br>
&gt; _______________________________________________<br>
&gt; swift-evolution mailing list<br>
&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div>