[swift-evolution] Proposal: Allow class cluster pattern via dynamic initializer return type

Charles Srstka cocoadev at charlessoft.com
Wed Dec 9 16:54:49 CST 2015


> On Dec 9, 2015, at 4:11 PM, Jean-Daniel Dupas via swift-evolution <swift-evolution at swift.org> wrote:
> 
> My experience with class cluster, is that they are confusing and almost implemented wrong. You can as easily create a « class cluster » simply be not exposing the constructor of your class and providing factory methods instead.

This is not possible with Swift, because it does not have a “private” access modifier. In order for subclasses to be able to override the abstract superclass’s designated initializer, that initializer has to be public. Callers can then call the initializer on the superclass and get undefined behavior.

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151209/fffa0c95/attachment.html>


More information about the swift-evolution mailing list