all 1 comments

[–]zyxzevn 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (0 children)

I often notice that the strategy pattern breaks.

I can explain it via the Algorithm() example: It works for sort variants, it is a relatively pure function with input and output. But many algorithms and optimizations are not so isolated. They need more than just a function-call.

For example with path-finding
You can have a hidden state, like a cache. Or do work in front by scanning the terrain to build a network. A network of paths that contain optimized paths from one area to another. So if you in one area, you only have to pick the paths from the graph. This front-work may be very costly, and would rather be done up-front, before any path-finding is done.
But if the terrain changes, you may need a new set of optimized paths. Or when all paths are blocked, you need special code that starts opening that path.

And these complex examples are more common than the simple sort() function. And they need insight in the whole state-dynamics of the system. Which can change dramatically when new features are added to the program.