Monday, March 12, 2018 [Tweets] [Favorites]

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.


Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment