<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 5 Jul 2016, at 08:01, Charlie Monroe via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div class=""><br class="">IMHO these things can be solved by private protocols with default implementation to reuse the code:<br class="">Or you can just create a private class and use its instance in your classes:<br class=""></div></div></blockquote></div><br class=""><div class="">The other alternative is to just declare the methods of the "private" class private/internal and then use them. For example:</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>public class Foo {</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>internal init() { … } // Can't be instantiated outside of this module</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>internal func doSomething() { … }</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>func publicMethod() { … }</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><font face="Monaco" class=""><br class=""></font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>public class Bar : Foo {</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>public init() { super.init() } // Can be instantiated outside of this module</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>public something() { super.doSomething() }</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><br class=""></div><div class="">But yeah, it seems like there are a lot of design patterns to solve this problem already; it's a nice idea, but proper abstract classes or traits/mixins are better possible solutions in the long-run, and the use of internal initialisers effectively result in abstract internal types for the time being.</div></body></html>