Proposal: Allow class cluster pattern via dynamic initializer return type

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

···

On Dec 9, 2015, at 4:11 PM, Jean-Daniel Dupas via swift-evolution <swift-evolution@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 was meant to say that Swift does not have “protected”, not “private”. Apologies for the typo.

Charles

···

On Dec 9, 2015, at 4:54 PM, Charles Srstka <cocoadev@charlessoft.com> wrote:

On Dec 9, 2015, at 4:11 PM, Jean-Daniel Dupas via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@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