> On 5 Jul 2016, at 08:01, Charlie Monroe via swift-evolution
> <[email protected]> wrote:
>
> IMHO these things can be solved by private protocols with default
> implementation to reuse the code:
> Or you can just create a private class and use its instance in your classes:
The other alternative is to just declare the methods of the "private" class
private/internal and then use them. For example:
public class Foo {
internal init() { … } // Can't be instantiated outside of this
module
internal func doSomething() { … }
func publicMethod() { … }
}
public class Bar : Foo {
public init() { super.init() } // Can be instantiated outside
of this module
public something() { super.doSomething() }
}
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._______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution