January 2020
Intermediate to advanced
470 pages
11h 13m
English
The Strategy pattern applies whenever you want to have the ability to change a class, method, or function, possibly in a dynamic way, by changing the way it actually does whatever it's expected to do. For example, a GPS application might want to find a route between two places by applying different strategies if the person is on foot, rides a bicycle, or goes by car. In that case, the fastest or the shortest routes might be desired. The problem is the same, but different algorithms must be applied, depending on the given condition.
By the way, does this sound familiar? If so, it is because we have already met a similar problem. When we wanted to sort a set of strings in different ways, in Chapter 3, Starting ...
Read now
Unlock full access