Strategy - behavioral pattern
The strategy pattern is a family of algorithms. The algorithms are created as separate program classes, fully interchangeable during runtime. At the top, we have a class that chooses an algorithm (but only one), which will be executed. When using this pattern, adding a new algorithm is as simple as creating a new implementation of the interface.
Modifying the algorithm just involves a modification of the proper method, as all algorithms are encapsulated into one method per algorithm. The strategy does not use inheritance, but only the implementation of the interface, so unnecessary linking is not created between the algorithm and methods using the algorithm. Using this method of behavior modification, the factory ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access