That is a very good point, it should be explicitly mentioned in the proposal. My thought would be that since in the Obj-C runtime it&#39;s not possible to guarantee a class won&#39;t have subclasses, or that a method is not overriden, Obj-C classes would be imported as open. <br><br>On the Swift side, I think today it&#39;s possible to declare a &quot;public final @objc class&quot;, but you can still inherit from it from Obj-C, right? My hunch would be that that should be disallowed, but perhaps there&#39;s a reason why it&#39;s allowed today. <br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 27, 2016 at 4:25 PM Michael Ilseman &lt;<a href="mailto:milseman@apple.com">milseman@apple.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Could you elaborate on how we should treat classes imported from Objective-C or CF-style C? That is, do we always annotate them as being “open” because those paradigms permit subclassing anywhere, or do you propose some kind of recommended “sealed” audit, or what?</div><br><div><blockquote type="cite"></blockquote></div></div><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On Jun 27, 2016, at 3:40 PM, Javier Soto via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></blockquote></div></div><div style="word-wrap:break-word"><div><blockquote type="cite"><div><div dir="ltr">Hello!<div><br></div><div>I sent this as a <a href="https://github.com/apple/swift-evolution/pull/376" target="_blank">PR</a> on the swift-evolution repo, but we never had any discussion about it on-list, besides <a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/9702/focus=9708" target="_blank">a long time ago</a>. Here&#39;s the first draft of the proposal:</div><div><br></div><div><br></div><div><h1 style="font-size:2.25em;margin:0px 0px 16px;line-height:1.2;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;">Sealed classes by default</h1><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a href="https://github.com/JaviSoto/swift-evolution/blob/a46877afb0302d2b03fa493255f5ced04ccb7f34/proposals/0000-sealed-by-default.md#introduction" style="color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1;background-color:transparent" target="_blank"></a>Introduction</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;line-height:25.6px">Introduce a new<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">sealed</code><span> </span>class modifier that makes classes and methods<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">final</code><span> </span>outside of the module they&#39;re declared in, but non-<code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">final</code><span> </span>within the module.</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a href="https://github.com/JaviSoto/swift-evolution/blob/a46877afb0302d2b03fa493255f5ced04ccb7f34/proposals/0000-sealed-by-default.md#motivation" style="color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1;background-color:transparent" target="_blank"></a>Motivation</h2><ul style="padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;line-height:25.6px"><li>It is not uncommon to have a need for a reference type without needing inheritance. Classes must be intentionally designed to be subclassable, carefully deciding which methods are the override entry-points such that the the behavior remains correct and subclasses respect the<span> </span><a href="https://en.wikipedia.org/wiki/Liskov_substitution_principle" style="color:rgb(64,120,192);text-decoration:none;background-color:transparent" target="_blank">Liskov substitution principle</a>.</li><li>Defaulting to non-<code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">final</code><span> </span>allows the author of a class to accidentally leave the visible methods open for overrides, even if they didn&#39;t carefully consider this possibility.</li><li>Requiring that the author of a class mark a class as<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">open</code><span> </span>is akin to requiring symbols to be explicitly<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">public</code>: it ensures that a conscious decision is made regarding whether the ability to subclass a<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">class</code><span> </span>is part of the API.</li></ul><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a href="https://github.com/JaviSoto/swift-evolution/blob/a46877afb0302d2b03fa493255f5ced04ccb7f34/proposals/0000-sealed-by-default.md#proposed-solution" style="color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1;background-color:transparent" target="_blank"></a>Proposed solution</h2><ul style="padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;line-height:25.6px"><li>New<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">sealed</code><span> </span><span style="line-height:25.6px">(</span><em style="line-height:25.6px">actual name pending bike-shedding</em><span style="line-height:25.6px">) </span>class modifier for classes and methods which marks them as only overridable within the module they&#39;re declared in.</li><li><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">sealed</code><span> </span>becomes the default for classes and methods.</li><li>New<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">open</code><span> </span>(<em>actual name pending bike-shedding</em>) class modifier to explicitly mark a class or a method as<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">overridable</code>.</li></ul><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a href="https://github.com/JaviSoto/swift-evolution/blob/a46877afb0302d2b03fa493255f5ced04ccb7f34/proposals/0000-sealed-by-default.md#detailed-design" style="color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1;background-color:transparent" target="_blank"></a>Detailed design</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;line-height:25.6px">Code Examples:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;line-height:25.6px"><pre style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;border-radius:3px;word-break:normal;background-color:rgb(247,247,247)"><span style="color:rgb(150,152,150)">/// ModuleA:</span>

<span style="color:rgb(150,152,150)">/// This class is `sealed` by default.</span>
<span style="color:rgb(150,152,150)">/// This is equivalent to `sealed class SealedParentClass`</span>
<span style="color:rgb(167,29,93)">class</span> SealedParentClass {
    <span style="color:rgb(150,152,150)">/// This method is `sealed` by default`.</span>
    <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">foo</span>()

    <span style="color:rgb(150,152,150)">/// This raises a compilation error: a method can&#39;t have a &quot;subclassability&quot;</span>
    <span style="color:rgb(150,152,150)">/// level higher than that of its class.</span>
    open <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">bar</span>()

    <span style="color:rgb(150,152,150)">/// The behavior of `final` methods remains unchanged.</span>
    <span style="color:rgb(167,29,93)">final</span> <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">baz</span>()
}

open <span style="color:rgb(167,29,93)">class</span> OpenParentClass {
    <span style="color:rgb(150,152,150)">/// This method is `sealed` by default`.</span>
    <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">foo</span>()

    <span style="color:rgb(150,152,150)">/// Overridable methods in an `open` class must be explicitly marked as `open`.</span>
    open <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">bar</span>()

    <span style="color:rgb(150,152,150)">/// The behavior of a `final` method remains unchanged.</span>
    <span style="color:rgb(167,29,93)">final</span> <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">baz</span>()
}

<span style="color:rgb(150,152,150)">/// The behavior of `final` classes remains unchanged.</span>
<span style="color:rgb(167,29,93)">final</span> <span style="color:rgb(167,29,93)">class</span> FinalClass { }</pre></div><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;line-height:25.6px"><pre style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;border-radius:3px;word-break:normal;background-color:rgb(247,247,247)"><span style="color:rgb(150,152,150)">/// ModuleB:</span>

<span style="color:rgb(167,29,93)">import</span> <span style="color:rgb(0,134,179)">ModuleA</span>

<span style="color:rgb(150,152,150)">/// This raises a compilation error: ParentClass is effectively `final` from</span>
<span style="color:rgb(150,152,150)">/// this module&#39;s point of view.</span>
<span style="color:rgb(167,29,93)">class</span> SubclassA <span style="color:rgb(167,29,93)">:</span> SealedParentClass { }

<span style="color:rgb(150,152,150)">/// This is allowed since `OpenParentClass` has been marked explicitly `open`</span>
<span style="color:rgb(167,29,93)">class</span> SubclassB <span style="color:rgb(167,29,93)">:</span> OpenParentClass {
    <span style="color:rgb(150,152,150)">/// This raises a compilation error: `OpenParentClass.foo` is</span>
    <span style="color:rgb(150,152,150)">/// effectively `final` outside of `ModuleA`.</span>
    <span style="color:rgb(167,29,93)">override</span> <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">foo</span>() { }

    <span style="color:rgb(150,152,150)">/// This is allowed since `OpenParentClass.bar` is explicitly `open`.</span>
    <span style="color:rgb(167,29,93)">override</span> <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">bar</span>() { }
}</pre></div><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a href="https://github.com/JaviSoto/swift-evolution/blob/a46877afb0302d2b03fa493255f5ced04ccb7f34/proposals/0000-sealed-by-default.md#impact-on-existing-code" style="color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1;background-color:transparent" target="_blank"></a>Impact on existing code</h2><ul style="padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;line-height:25.6px"><li>This would be a backwards-breaking change for all classes and methods that are public and non-final, which code outside of their module has overriden. Those classes/methods would fail to compile. Their superclass would need to be changed to<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">open</code>.</li></ul><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a href="https://github.com/JaviSoto/swift-evolution/blob/a46877afb0302d2b03fa493255f5ced04ccb7f34/proposals/0000-sealed-by-default.md#alternatives-considered" style="color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1;background-color:transparent" target="_blank"></a>Alternatives considered</h2><ul style="padding-left:2em;margin-top:0px;color:rgb(51,51,51);font-family:&quot;helvetica neue&quot;,helvetica,&quot;segoe ui&quot;,arial,freesans,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;line-height:25.6px;margin-bottom:0px"><li>Defaulting to<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">final</code><span> </span>instead: This would be comparable to Swift defaulting to<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">private</code>, as opposed to<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">internal</code>. Just like<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">internal</code><span> </span>is a better trade-off,<span> </span><code style="font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">sealed</code><span> </span>by default also makes sure that getting started with Swift, writing code within a module, doesn&#39;t require a lot of boilerplate, and fighting against the compiler.</li></ul></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">Javier Soto</div></div></div></blockquote></div></div><div style="word-wrap:break-word"><div><blockquote type="cite"><div>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">Javier Soto</div></div>