In: Computer Science
Briefly describe an example scenario where a strategy design pattern is suitable to use.
The pattern of strategy design is a kind of pattern of behavioural design that encapsulates a "family" of algorithms and selects one for use during runtime from the pool. The algorithms are interchangeable, which means they can be replaced by each other. The key concept is to create objects that represent different strategies. Such objects form a pool of approaches from which the background object may choose to modify its actions according to its approach. The same process is done by these objects(strategies), they have the same(single) task and write the same interface strategy.
For an example lets take sorting problem. To efficiently philtre an assortment of numbers, these algorithms have a set of rules unique to each other that they obey. For example consider the following;
Then, we need various algorithms during execution in our software. Using strategy design pattern enables us to group these algorithms and, as appropriate, pick from the pool.