Design Patterns · Junior · Question 8 of 75
What is the Strategy pattern?
- ✓Correct answer: A family of interchangeable algorithms chosen at runtime
- 2A quarterly project development plan approved by the architect
- 3An order of method calls hard-coded in the base class of a hierarchy
Explanation
Instead of a long if/else by delivery type - a strategies object { courier: calcCourier, pickup: calcPickup }, and the code calls the right one. A JS example is the compare function in sort(compareFn): the sorting algorithm stays the same, while the comparison strategy is plugged in.