Design Patterns · Junior · Question 8 of 75

What is the Strategy pattern?

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.

Further reading

Problem with a question

Design Patterns · Junior · question 8

Test yourself

Take the Design Patterns · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz