December 2018
Intermediate to advanced
414 pages
10h 19m
English
The strategy pattern involves only a few components:
Let's attempt to generalize this implementation via protocols.
Strategy is the algorithm that runs the code, and that will be swapped at runtime. At a high level, a strategy is only dependent on its algorithm ReturnType:
protocol Strategy { associatedtype ReturnType func run() -> ReturnType}
In practice, this abstraction lacks some definition, as we're missing some information about what we should pass to the algorithm. For the sake of our demonstration, let's rewrite the run() function with a single argument. As we're using generics, this argument ...
Read now
Unlock full access