Monday, March 12, 2018

Better Strategies Through Types

Joshua Emmons:

We have to limit our delegate to class implementations because delegates are assumed to hold mutable state.

[…]

So rather than holding our strategy’s implementation in instance methods that need to be instantiated, we’re going to move it all up into type methods on the type.

[…]

If all this .Type and .self stuff feels a little awkward, it’s probably because Swift already supports this kind of thing as a language feature. It has a specific syntax just for passing around types that are used to specialize implementations. We know it as “generics”.

However, a key difference is that, unlike delegates, the type cannot change at runtime.

Comments RSS · Twitter

Leave a Comment